Unity3D - Making an object follow the other with the same velocity (variable speed)
I have two circles in the same scene, and I need one of them repeat the same motion that other place. Only keeping the distance from the size of the other.
Considering circle "A" and circle "B", I'm storing the circle coordinate "A" on an array of positions, then the circle "B" reads these positions and performs.
With this methodology I face problems when increasing the speed circle "A", because as the circle "B" still reading the array the speed that was previously stored, making circles to separate.
See the image:
Ideally, the circle "B" run on the current speed of the circle "A", but it will never be possible to be reading from an array already recorded with the speed of circle "A" at that time.
var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.AngleAxis(angle, Vector3.forward), 180 * Time.deltaTime);
transform.position += transform.right * Time.deltaTime * velocity;
Camera.main.transform.position = new Vector3(transform.position.x, transform.position.y, Camera.main.transform.position.z);
recordList.Insert(0, new Recorder
{
Position = transform.position,
Rotation = transform.rotation,
Velocity = velocity
});
What would be the best way to make this scenario?
I appreciate any help in advance!
Answer by Arsineh · May 25, 2016 at 12:44 PM
Add Fixed joint component to the object "A" and add the object "B" in connected body field and they will move with the same speed.
Hope that helps
Hi @Arsineh, thanks for your reply! But still need to read the array of positions, otherwise it will not have the effect of "snake" . It will seem one hard object without flexibility.
@IgorUnity3D Hi,
Have you tried public GameObject[] yourObjectsArray;
?
@Arsineh Sorry but... you tried your solution?