- Home /
Triggering movement from touching gameObject (Javascript issue)
Heya UnityAnswers
(Using the latest version of Unity) Here's what I want to happen, A sphere moving down a path way at a constant pace coming into contact with a series of cubes. When the sphere touches a cube, the cube will move up (Y) and move back down.
I set a tag on the sphere named "Ball" and started to try and script the event...I'll add in // to explain what I assume...
//Collider function
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Ball")
{
gotHit = true;
print("HIT");
}
}
//aka if the cube is hit by the object tagged "Ball"
//it will set gotHit as true. Also it'll print that
//it got hit in the console
function LateUpdate()
{
if(gotHit)
{
move = true;
gameObject.transform.position == Vector3(0, 3, 0);
gameObject.transform.position == Vector3(0, -3, 0);
print("MOVE");
}
}
//if gotHit is true it'll move the cube upwards along the Y axis
//then back down to where it started
//as well as print "MOVE" in the console
I've set the cubes and spheres(Ball) collider as triggers and animated the sphere using the inbuilt animation feature yet when it reaches the cube there's no movement and no printing D:
I'm just starting out at writing my own script and my understanding of how the collider works is from a tutorial where the player touches a cube and they respawn (transform) back to the starting postion. It works there but not here and I must be missing something fairly blatant that I don't see. Any help to iron this out would be great! Thanks ahead!
Lines 20 and 21 you use ==
when you mean =
. The ==
means has the same value as, =
means assign.
Answer by MSB · Mar 21, 2013 at 03:48 PM
I'm starting all again and using http://www.unity3dstudent.com/2010/07/beginner-b01-basic-collision-detection/
Your answer
Follow this Question
Related Questions
Problem using rotation and Rotate 1 Answer
Strange position change when triggered 0 Answers
How can i Limit the Mouse X Axis for Mouse Look 3 Answers
move camera when it collides with a trigger 1 Answer
Best Way to make a character move 1 Answer