- Home /
Question by
ClownOfMadness · Feb 18, 2020 at 05:50 PM ·
2d gamedistancevector2
[Please Help] 2D keeping an object within a fixed radius from main object
Hello.
Im trying to make a certain sprite to follow mouse position but stay within a fixed radius from the main player sprite, so it will look like it only circles around the player. i need to only lock the distance of from another without touching rotation of the object as i need them to stay in the same rotation. the game isn't a clean 2D axis game, I am using the z and x axis. void StepRotateMovement() { lockedDistance = Vector3.Distance(shadow.transform.position, transform.position);
shadow.transform.position = convertedMousePosition;
if (lockedDistance != 3f)
{
Vector3 fromOriginToObject = shadow.transform.position - transform.position;
fromOriginToObject *= 3f / lockedDistance;
shadow.transform.position = transform.position + fromOriginToObject;
}
}
This is what I tried doing but as of result i am getting the shadow object to glitch infinitely between the center and its new position. besides that it doesn't lock its distance and instead it only reduces it.
Thank you in advance!
Comment