This commit is contained in:
kimrdd 2024-02-03 03:28:32 +01:00
commit 56bd4edde9
15 changed files with 577 additions and 21 deletions

8
Assets/Plugins.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d39ba45ecabd2ad4299936d779e04123
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e439084cec60bc94dafe5b98c4da7dcc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,21 @@
fileFormatVersion: 2
guid: 78d74b9d68578864f928989b03e03bbb
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- CozetteVector
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b6d096bc62a8f1e498a98e3722766b77
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: b6d1ddbaa0d99de45909cb04c0f0e5f4
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,3 @@
{
"name": "Project.Plugins.ZFolderIcons"
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9d8ac3893a2ccdf40aaf2fe4f42a5b14
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,346 @@
#if UNITY_EDITOR && UNITY_2021_3_OR_NEWER
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
using UnityEngine.Windows;
[InitializeOnLoad]
public class ZFolderIcons : EditorWindow
{
private static GUIStyle DirectoryLabelStyle;
private static GUIStyle MonoScriptLabelStyle;
private const float maxHeight = 18f;
private static Texture2D scriptIconTexture;
private static Dictionary<Regex, string> PreDefinedFolderLabels = new Dictionary<Regex, string>
{
{
new Regex(@"^Script(s)?$", RegexOptions.IgnoreCase),
"C#"
},
{
new Regex(@"^Plugin(s)?$", RegexOptions.IgnoreCase),
"Plug"
},
{
new Regex(@"^Resource(s)?$", RegexOptions.IgnoreCase),
"Res"
},
{
new Regex(@"^Editor$", RegexOptions.IgnoreCase),
"Edit"
},
{
new Regex(@"^Prefab(s)?$", RegexOptions.IgnoreCase),
"PF"
},
{
new Regex(@"^Tile(s)?Palette(s)?$", RegexOptions.IgnoreCase),
"Tile"
},
};
static ZFolderIcons()
{
EditorApplication.projectWindowItemOnGUI += OnProjectWindowItemGUI;
}
private static void OnProjectWindowItemGUI(string guid, Rect selectionRect)
{
if (selectionRect.height < maxHeight)
return;
// Get the asset path based on the GUID
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
// Check if the asset is a folder and not in the base project folder
// Use "&& assetPath.Count(c => c == '/') >= 2" to ignore base assets folder
// TODO: Impliment AssetDatabase.GetMainAssetTypeFromGUID(new GUID(guid)).IsSubclassOf(typeof(ScriptableObject))
Type objectType = null;
if (AssetDatabase.IsValidFolder(assetPath))
{
DoFolderIcons(assetPath, selectionRect);
}
else
{
objectType = AssetDatabase.GetMainAssetTypeFromGUID(new GUID(guid));
}
if (objectType == null) return;
if (objectType == typeof(MonoScript)) // Is script object
{
DoMonoScriptIcon(assetPath, selectionRect);
}
}
static void DoFolderIcons(string folderPath, Rect selectionRect)
{
// Calculate the position for the custom label
Rect labelRect = new Rect(selectionRect.x + selectionRect.width * 0.15f, selectionRect.y + selectionRect.width * 0.4f, selectionRect.width, selectionRect.height);
string folderName = Path.GetFileName(folderPath);
// Create GUIStyle if it hasn't been created yet
if (DirectoryLabelStyle == null)
{
DirectoryLabelStyle = new GUIStyle(EditorStyles.miniLabel);
DirectoryLabelStyle.alignment = TextAnchor.UpperLeft; // Adjust the font size as desired
DirectoryLabelStyle.normal.textColor = Color.black; // Set the text color
TryAssignFont(ref DirectoryLabelStyle);
}
DirectoryLabelStyle.fontSize = (int)(selectionRect.width * 0.35f); // Adjust the font size as desired
string labelText;
if (TryGetPreDefinedLabel(folderName, out string label))
{
labelText = label;
}
else if (folderName.Count(char.IsUpper) >= 2)
{
labelText = new string(folderName.Where(x => char.IsUpper(x)).Take(4).ToArray());
}
else
{
labelText = new(folderName.Take(4).ToArray());
}
// Draw the custom label with black color
var previousColor = GUI.color;
GUI.color = Color.black;
EditorGUI.LabelField(labelRect, labelText, DirectoryLabelStyle);
GUI.color = previousColor;
DrawFolderColorStrip(folderName, selectionRect);
}
static void DrawFolderColorStrip(string seedString, Rect selectionRect)
{
Color stripColor = GetRandomColor(seedString);
// Calculate the position for the strip
Rect stripRect = new Rect(
x: selectionRect.x + selectionRect.width * 0.175f,
y: selectionRect.y + selectionRect.width * 0.725f,
width: selectionRect.width * 0.64f,
height: selectionRect.height * 0.05f);
// Draw the custom label with black color
var previousColor = GUI.color;
EditorGUI.DrawRect(stripRect, stripColor);
GUI.color = previousColor;
}
static void DoMonoScriptIcon(string scriptPath, Rect selectionRect)
{
// Calculate the position for the white overlay
Rect overwriteOverlayRect = new Rect(selectionRect.x + selectionRect.width * 0.25f, selectionRect.y + selectionRect.width * 0.20f, selectionRect.width*0.5f, selectionRect.height*0.5f);
var previousColor = GUI.color;
if (!Application.isPlaying)
{
// Draw the custom rect with white color
previousColor = GUI.color;
float shadeOfWhite = 247;
GUI.color = new Color(shadeOfWhite / 255f, shadeOfWhite / 255f, shadeOfWhite / 255f);
EditorGUI.DrawRect(overwriteOverlayRect, GUI.color);
GUI.color = previousColor;
}
else
{
//Did not work
//// Gets playmode tint color
//string prefPlaymodeTint = EditorPrefs.GetString("Playmode tint", "").Replace("Playmode tint;", "");
//string[] rgba = prefPlaymodeTint.Split(";");
//Color color = new Color(float.Parse(rgba[0]), float.Parse(rgba[1]), float.Parse(rgba[2]), float.Parse(rgba[3]));
//// Draw the custom rect with play color tint
//previousColor = GUI.color;
//GUI.color = color;
//EditorGUI.DrawRect(overwriteOverlayRect, GUI.color);
//GUI.color = previousColor;
// Draw the custom rect with white color
previousColor = GUI.color;
float shadeOfWhite = 247;
GUI.color = new Color(shadeOfWhite / 255f, shadeOfWhite / 255f, shadeOfWhite / 255f);
EditorGUI.DrawRect(overwriteOverlayRect, GUI.color);
GUI.color = previousColor;
}
string scriptName = Path.GetFileName(scriptPath);
const int maxLength = 8;
string labelText;
{
// Use LINQ to iterate through each character and insert a line break before uppercase letters
labelText = new string(scriptName.SelectMany(c => char.IsUpper(c) ? new char[] { '\n', c } : new[] { c }).ToArray());
labelText = labelText.TrimStart('\n').Replace(".cs", "");
labelText = string.Join('\n', MergeLooseCapitalStrings(labelText.Split('\n')));
labelText = string.Join('\n', labelText.Split('\n').Select(x => x.Length > 6 ? new string(x.Take(maxLength).ToArray()) + "…" : x));
}
// Calculate the position for the custom label
Rect labelRect = new Rect(selectionRect.x + selectionRect.width * 0.15f, selectionRect.y + selectionRect.width * 0.1f, selectionRect.width, selectionRect.height);
// Create GUIStyle if it hasn't been created yet
if (MonoScriptLabelStyle == null)
{
MonoScriptLabelStyle = new GUIStyle(EditorStyles.miniLabel);
MonoScriptLabelStyle.alignment = TextAnchor.UpperLeft; // Adjust the font size as desired
MonoScriptLabelStyle.normal.textColor = Color.black; // Set the text color
TryAssignFont(ref MonoScriptLabelStyle);
}
MonoScriptLabelStyle.fontSize = (int)(selectionRect.width * 0.2f); // Adjust the font size as desired
// Draw the custom label with black color
previousColor = GUI.color;
GUI.color = Color.black;
EditorGUI.LabelField(labelRect, labelText, MonoScriptLabelStyle);
GUI.color = previousColor;
// Custom icon rect
Rect customIconRect = new Rect(selectionRect.x + selectionRect.width * 0.62f, selectionRect.y + selectionRect.width * 0.645f, selectionRect.width * 0.25f, selectionRect.height * 0.25f);
// Load texture if null
if (scriptIconTexture == null)
{
if (TryGetScriptIcon(out Texture2D icon))
{
scriptIconTexture = icon;
}
else
{
return; // Couldn't get icon, so don't draw it
}
}
// Draw the custom icon
GUI.DrawTexture(customIconRect, scriptIconTexture);
}
public static bool TryGetPreDefinedLabel(string folderName, out string label)
{
foreach (var regex in PreDefinedFolderLabels.Keys)
{
if (regex.IsMatch(folderName))
{
label = PreDefinedFolderLabels[regex];
return true;
}
}
label = "Error";
return false;
}
static bool TryGetScriptIcon(out Texture2D icon)
{
if (FindFolder("ExtraIcons", out string path))
{
icon = AssetDatabase.LoadAssetAtPath<Texture2D>(path + "/ScriptHashtag.png");
return true;
}
else
{
icon = null;
return false;
}
}
static bool FindFolder(string folderName, out string path)
{
string[] guids = AssetDatabase.FindAssets("t:Folder " + folderName);
if (guids.Length > 0)
{
path = AssetDatabase.GUIDToAssetPath(guids[0]);
return true;
}
else
{
path = null;
return false;
}
}
static string[] MergeLooseCapitalStrings(string[] arr)
{
List<string> result = new List<string>();
string currentString = "";
foreach (string s in arr)
{
if (IsUpperCase(s))
{
currentString += s;
}
else if (!string.IsNullOrEmpty(currentString))
{
result.Add(currentString + s);
currentString = "";
}
else
{
result.Add(s);
}
}
if (!string.IsNullOrEmpty(currentString))
{
result.Add(currentString);
}
return result.ToArray();
}
static Func<string, bool> IsUpperCase = s => !string.IsNullOrEmpty(s) && s.All(char.IsUpper);
/// <summary>
/// Generates a semi random color out of a seed
/// </summary>
/// <param name="seed">Used to generate the color</param>
/// <returns>A semi random color</returns>
public static Color GetRandomColor(string seed)
{
int intSeed = seed.Select(c=>(int)c).Sum();
System.Random random = new System.Random(intSeed);
// Generate random values for R, G, and B components between 0 and 1.
float r = (float)random.NextDouble();
float g = (float)random.NextDouble();
float b = (float)random.NextDouble();
// Create and return the color.
return new Color(r, g, b);
}
private static void TryAssignFont(ref GUIStyle guiFont)
{
string[] guids = AssetDatabase.FindAssets("t:Font CozetteVector", new[] { "Assets/Plugins/ZFolderIcons" });
if (guids.Length <= 0)
{
return; // Couldn't find font asset
}
string path = AssetDatabase.GUIDToAssetPath(guids[0]);
guiFont.font = AssetDatabase.LoadAssetAtPath<Font>(path);
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 492e529bdc9cf034989956b1d941225e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1515,7 +1515,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 27ac133d9e10e544ba603e07122e3359, type: 3} m_Script: {fileID: 11500000, guid: 27ac133d9e10e544ba603e07122e3359, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
gravity: 0 gravity: 15
solveIterations: 10 solveIterations: 10
constrainStickMinLength: 0 constrainStickMinLength: 0
start: {fileID: 1451580753} start: {fileID: 1451580753}
@ -1530,6 +1530,7 @@ MonoBehaviour:
serializedVersion: 2 serializedVersion: 2
m_Bits: 1 m_Bits: 1
pullForce: 65 pullForce: 65
xyGravityDampScalor: 1
lineRenderer: {fileID: 1973576218} lineRenderer: {fileID: 1973576218}
testPos: {x: 0, y: 0} testPos: {x: 0, y: 0}
--- !u!120 &1973576218 --- !u!120 &1973576218

View File

@ -33,7 +33,6 @@ public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver
public void TakeSquezeDamage(float squezeDamage) public void TakeSquezeDamage(float squezeDamage)
{ {
Debug.Log($"Taking {squezeDamage}");
if (squezeDamage < minThreshold) return; if (squezeDamage < minThreshold) return;
TakeDamage((int) Mathf.Round(squezeDamage * squezeDamageScalor)); TakeDamage((int) Mathf.Round(squezeDamage * squezeDamageScalor));

View File

@ -3,10 +3,10 @@ using UnityEngine;
[System.Serializable] [System.Serializable]
public class Point public class Point
{ {
public Vector2 position, prevPosition; public Vector3 position, prevPosition;
public bool locked; public bool locked;
public Point(Vector2 position, bool locked = false) public Point(Vector3 position, bool locked = false)
{ {
this.position = position; this.position = position;
this.prevPosition = position; this.prevPosition = position;

View File

@ -47,6 +47,9 @@ public class RopeSimulator : MonoBehaviour
[SerializeField, Range(0f, 100f)] [SerializeField, Range(0f, 100f)]
float pullForce = 20f; float pullForce = 20f;
[SerializeField]
float xyGravityDampScalor = 1f;
[Header("Rendering")] [Header("Rendering")]
[SerializeField] LineRenderer lineRenderer; [SerializeField] LineRenderer lineRenderer;
@ -75,7 +78,7 @@ public class RopeSimulator : MonoBehaviour
builder.AddPoint(new Point(start.position, locked: true)); builder.AddPoint(new Point(start.position, locked: true));
for (int i = 1; i < subDivision; i++) for (int i = 1; i < subDivision; i++)
{ {
Vector2 pointPos = Vector2.Lerp(start.position, end.position, (float)i / (float)subDivision); Vector3 pointPos = Vector3.Lerp(start.position, end.position, (float)i / (float)subDivision);
//Debug.Log($"pos: {pointPos}, t={i / subDivision}"); //Debug.Log($"pos: {pointPos}, t={i / subDivision}");
Debug.DrawRay(pointPos, (end.position - start.position).normalized); Debug.DrawRay(pointPos, (end.position - start.position).normalized);
builder.AddPoint(new Point(pointPos)); builder.AddPoint(new Point(pointPos));
@ -93,6 +96,7 @@ public class RopeSimulator : MonoBehaviour
{ {
GameObject ropeCollider = new GameObject("Rope Collider"); GameObject ropeCollider = new GameObject("Rope Collider");
ropeCollider.transform.parent = ropeCollidersParent; ropeCollider.transform.parent = ropeCollidersParent;
ropeCollider.transform.position = point.position;
ropeCollider.layer = LayerMask.NameToLayer("Rope"); ropeCollider.layer = LayerMask.NameToLayer("Rope");
var colliderComponent = ropeCollider.AddComponent<CircleCollider2D>(); var colliderComponent = ropeCollider.AddComponent<CircleCollider2D>();
@ -129,7 +133,7 @@ public class RopeSimulator : MonoBehaviour
if (overshoot > 0) if (overshoot > 0)
{ {
//start.position = prevStartPos; //start.position = prevStartPos;
Vector2 pullDirection = (rope.points.ElementAt(1).position - new Vector2(start.position.x, start.position.y)).normalized; Vector2 pullDirection = (rope.points.ElementAt(1).position - start.position).normalized;
start.gameObject.GetComponent<Rigidbody2D>().AddForce(pullDirection * overshoot * pullForce); start.gameObject.GetComponent<Rigidbody2D>().AddForce(pullDirection * overshoot * pullForce);
} }
@ -146,6 +150,15 @@ public class RopeSimulator : MonoBehaviour
var positions = rope.points.Select(p => new Vector3(p.position.x, p.position.y, 0f)).ToArray(); var positions = rope.points.Select(p => new Vector3(p.position.x, p.position.y, 0f)).ToArray();
lineRenderer.positionCount = positions.Length; lineRenderer.positionCount = positions.Length;
lineRenderer.SetPositions(positions); lineRenderer.SetPositions(positions);
// Handle xy dampening on z gravity
foreach (var point in rope.points)
{
if (point.position.z >= 0f) continue;
Vector2 newXYPos = Vector2.MoveTowards(new Vector2(point.position.x, point.position.y), new Vector2(point.prevPosition.x, point.prevPosition.y), Mathf.Abs(point.position.z * xyGravityDampScalor));
point.position.Set(newXYPos.x, newXYPos.y, 0f);
}
} }
private void OnDrawGizmos() private void OnDrawGizmos()
@ -165,9 +178,9 @@ public class RopeSimulator : MonoBehaviour
{ {
if (!p.locked) if (!p.locked)
{ {
Vector2 positionBeforeUpdate = p.position; Vector3 positionBeforeUpdate = p.position;
p.position += p.position - p.prevPosition; p.position += p.position - p.prevPosition;
p.position += Vector2.down * gravity * Time.deltaTime * Time.deltaTime; p.position.z -= gravity * Time.deltaTime * Time.deltaTime;
p.prevPosition = positionBeforeUpdate; p.prevPosition = positionBeforeUpdate;
} }
} }
@ -182,8 +195,8 @@ public class RopeSimulator : MonoBehaviour
continue; continue;
} }
Vector2 stickCentre = (stick.A.position + stick.B.position) / 2; Vector3 stickCentre = (stick.A.position + stick.B.position) / 2;
Vector2 stickDir = (stick.A.position - stick.B.position).normalized; Vector3 stickDir = (stick.A.position - stick.B.position).normalized;
float length = (stick.A.position - stick.B.position).magnitude; float length = (stick.A.position - stick.B.position).magnitude;
if (length > stick.desiredLength || constrainStickMinLength) if (length > stick.desiredLength || constrainStickMinLength)
@ -201,16 +214,17 @@ public class RopeSimulator : MonoBehaviour
} }
} }
private void TryMovePointToPosition(Point point, Vector2 position) private void TryMovePointToPosition(Point point, Vector3 position)
{ {
Vector2 moveDir = position - point.position; Vector2 moveDir = new Vector2(position.x, position.y) - new Vector2(point.position.x, point.position.y);
int stepsRequired = (int) Mathf.Ceil(moveDir.magnitude / collisionCheckDist); int stepsRequired = (int) Mathf.Ceil(moveDir.magnitude / collisionCheckDist);
moveDir.Normalize(); moveDir.Normalize();
Vector2 initialPos = point.position;
Vector2 initialPos = new Vector2(point.position.x, point.position.y);
for (int i = 0 ; i < stepsRequired; i++) for (int i = 0 ; i < stepsRequired; i++)
{ {
Vector2 newPos = Vector2.MoveTowards(point.position, position, collisionCheckDist); Vector2 newPos = Vector2.MoveTowards(new Vector2(point.position.x, point.position.y), new Vector2(position.x, position.y), collisionCheckDist);
point.position = newPos; point.position.Set(newPos.x, newPos.y, point.position.z);
Collider2D collider = Physics2D.OverlapCircle(point.position, ropeRadius, staticColliderMask); Collider2D collider = Physics2D.OverlapCircle(point.position, ropeRadius, staticColliderMask);
if (collider == null) continue; if (collider == null) continue;
@ -219,13 +233,15 @@ public class RopeSimulator : MonoBehaviour
if (Vector2.Distance(initialPos, resolvedPos) < ignoreResolveThreshold) continue; if (Vector2.Distance(initialPos, resolvedPos) < ignoreResolveThreshold) continue;
Vector2 penetrationDir = (resolvedPos - point.position).normalized; Vector2 penetrationDir = (resolvedPos - new Vector2(point.position.x, point.position.y)).normalized;
Vector2 finalPos = resolvedPos - penetrationDir * ropeRadius; Vector2 finalPos = resolvedPos - penetrationDir * ropeRadius;
//Debug.Log($"resolved pos: {point.position}->{finalPos}"); //Debug.Log($"resolved pos: {point.position}->{finalPos}");
point.position = finalPos; point.position.Set(finalPos.x, finalPos.y, point.position.z);
//point.prevPosition = finalPos;
break; break;
} }
// Move z position
point.position.z = position.z;
} }
private void HandleStaticCollidersOfPoint(Point p) private void HandleStaticCollidersOfPoint(Point p)
@ -234,8 +250,9 @@ public class RopeSimulator : MonoBehaviour
if (hitCollider == null) return; if (hitCollider == null) return;
// Register the squeze force this rope particle is squezing the collider // Register the squeze force this rope particle is squezing the collider
Vector2 resolvedPos = hitCollider.ClosestPoint(p.position); Vector2 pointPos = new Vector2(p.position.x, p.position.y);
Vector2 penetration = resolvedPos - p.position; Vector2 resolvedPos = hitCollider.ClosestPoint(pointPos);
Vector2 penetration = resolvedPos - pointPos;
Vector2 finalPos = resolvedPos - penetration.normalized * ropeRadius; Vector2 finalPos = resolvedPos - penetration.normalized * ropeRadius;
float squezeForce; float squezeForce;
@ -244,7 +261,7 @@ public class RopeSimulator : MonoBehaviour
else else
colliderToSquezeForce[hitCollider] = squezeForce + penetration.magnitude; colliderToSquezeForce[hitCollider] = squezeForce + penetration.magnitude;
p.position = finalPos; p.position.Set(finalPos.x, finalPos.y, p.position.z);
} }
void CreateOrderArray() void CreateOrderArray()