- Home /
Why isn't my move on collision script working?
I have a script that works as follows: It is assigned to a door object that is supposed to move up when it collides with the DoorChecker object which is a child object of the Player. The DoorChecker has the Door tag assigned to it and the script is set to activate on collision with an object carrying the Door tag. However, when I run it the door doesn't move at all.
Here is my script:
var thePositionToMoveTo : Vector3;
var theTag : String;
var speed : float;
function OnCollisionEnter2D(other : Collision2D) {
if(other.gameObject.tag == theTag) {
transform.position = Vector3.MoveTowards(transform.position, thePositionToMoveTo, speed);
}
}
I have variables for the position it is meant to move towards, the tag it's looking for, and the speed at which the object moves towards its destination.
Thanks in advance for any help.
Your answer
Follow this Question
Related Questions
SetActive messes up everything? 1 Answer
Help with Mobile Game controls 2 Answers
Why is my collision script not working? 1 Answer
Glitchy collisions 0 Answers
2D Movement with axis? 1 Answer