Hello everyone I have 2 rigidbodys with scripts attached. I made the first script to change the rotation of an object1 and the speed to negative(just because the controls would not go reverse) when the object1 X coordinates are bigger than object2 X coordinates. The problem is that when the object1 coordinates gets bigger than the object2, object1 gets stuck in that position and goes bugy. I don’t understand why does that happen and I would really appreciate your help. Here is the video of my problem https://www.youtube.com/watch?v=1yjfxz1W17I, I find it difficult to explain this by writing
The object1(player1) move script:
var object1 : Transform;
var object2 : Transform;
var Xspeed = 10.0;
var Yspeed = 10.0;
function Start() {
}
function FixedUpdate () {
var x = Input.GetAxis("Horizontal") * Time.deltaTime * Xspeed;
var y = Input.GetAxis("Vertical") * Time.deltaTime * Yspeed;
transform.Translate(x, y, 0);
if(object1.transform.position.x > object2.transform.position.x){
transform.Rotate(new Vector3(0,180,0));
Xspeed = -10.0;
print("Rotating");
}
else{
transform.Rotate(new Vector3(0,0,0));
Xspeed = 10.0;
print("RotatingBack");
}
}
The object2(player2) move script:
#pragma strict
var speed = 10.0;
function FixedUpdate () {
var x = Input.GetAxis("Horizontal2") * Time.deltaTime * speed;
var y = Input.GetAxis("Vertical2") * Time.deltaTime * speed;
transform.Translate(x, y, 0);
}