Hi everyone, I’m having a difficult time trying to make a very simple animation.
I have a sphere (testObject1) which I want to move left and right, and switch this movement when it collides to with a rigidbody.
So, I came up with this:
var speed = 0.10;
var dropPoint = 1;
function Update () {
if(dropPoint == 1){
transform.Translate(0, 0, speed);
}else{
transform.Translate(0, 0, speed - (speed * 2));
}
}
function OnCollisionEnter(collision : Collision) {
for (var contact : ContactPoint in collision.contacts) {
if(collision.collider == "testObject3"){
dropPoint = 2;
}else{
if(collision.collider == "testObject2"){
dropPoint = 1;
}
}
if(collision.collider != "testFloor"){
print(collision.collider);
}
}
}
So, when I hit play, the sphere starts moving in Z direction, collides with the testObject3 and it keeps going in the same direction…
What am I doing wrong here?
Thanks!