I was hoping I’d be able to calculate the movement of objects without using things like Transform.forward. Purely from a abstract rotation and position. Is there a general rule to this?
I am right now trying to make a object move a 50 Unity units away from another object’s origin, along a random direction upon the z axis (as if it’s 2D). Is there a way to calculate this without using Transform.forward or Transform.Translate().
I was hoping I could have something along the lines of:
public static Vector3 GetRandomPosition(GameObject map, GameObject _plyrAnchor)
{
if (!bInitialised)
{
Debug.Log("GridReference.GetRandomMapPosition - Class not yet processed initialisation!");
return Vector3.zero;
}
Vector3 _toMapPoint = map.transform.InverseTransformPoint(_plyrAnchor.transform.position);
Vector3 working = default(Vector3);
Vector3 random_EulerRotation = new Vector3(0,0, Random.Range(0, 360));
working = random_EulerRotation * 50;
working += _toMapPoint;
working = map.transform.TransformPoint(working);
return working;
}
What is the method? Or is there a specific set of maths you’d suggest I learn to master this?
I know there’s workarounds like making an empty gameobject and moving along rotations and things, but I want to learn lol.
Your question and your code don’t really make sense
There is no z axis in 2D, and you are adding random_EulerRotation to your working position (rotation plus position is not a thing)
Draw a pic for full clarity
The only bit i can guess at for now is
//I am right now trying to make a object (B) move a 50 Unity units away from another object's origin (A)
Vector3 AtoB = B.transform.position - A.transform.position;
Vector3 FiftyUnitsAway = B.transform.position + AtoB.normalised * 50
Lysander that’s almost exactly what I’m after, however it’s returning a different distance between the two targets everytime. Instead of a fixed value (50). Even though it says the magnitude is correct.
There is no classes attached to the object’s themselves that might affect their position in any other way. The only class which moves them is this class. So it must be in this positioning, which sends their distance backwards.
I honestly don’t see the point of converting the point to and from the map’s local space coordinates. Also, the start position and goal position likely have two entirely different Z values, which is throwing this off- assign startPos.z to goalPos.z when assigning the newX and newY values.