I have created a scene with a plane, a platform (4 X 0.25 X 4 box) in the origin and some capsules that run towards the origin (when they touch the origin they stop to move). But the capsule in the center start jump over the other capsules. How can I solve this problem?
public class Capsule : MonoBehaviour {
bool touch;
void Start() {
transform.position=new Vector3(UnityEngine.Random.Range(-25.0f,+25.0f),1.0f,UnityEngine.Random.Range(-25.0f,+25.0f));
touch=false;
}
void FixedUpdate() {
Vector2 p=new Vector2();
if(!touch Vector3.Distance(new Vector3(0.0f,rigidbody.position.y,0.0f),rigidbody.position)>0.5f) {
p.x=rigidbody.position.x;
p.y=rigidbody.position.z;
p=p-p.normalized*4.0f*Time.fixedDeltaTime;
rigidbody.MovePosition(new Vector3(p.x,rigidbody.position.y,p.y));
}
else {
touch=true;
}
}
}