- Home /
up and down detect
how in script to detect if the object was moved within y axis?, i have a gameobject that should be moved up and down
Answer by Berenger · Feb 13, 2012 at 05:02 AM
In general, store the last position in a variable and check if the distance from the current position is greater than an epsilon. In your case, just do it with the y component.
is this how i should do it?
var lastposition : (whatsthedatatypeforthis?);
var transform.position.y = 0; if (lastposition != transform.position.y){ Debug.log = "moved" }
If you just want a test on the height, it's a float then. Something like :
var lastHeight : float; // renamed to be more coherent
function Update()
{
// It's better to do it that way, float comparison can give you surprises due to lack of precision.
if( $$anonymous$$athf.Absolute( lastHeight - transform.position.y ) > 0.1F )
{}// Here the height changed, to whatever you need to
lastHeight = transform.position.y;
}
Your answer
Follow this Question
Related Questions
Making a Paddle Move Vertically? 1 Answer
Restrict camera rotation in x and y? 1 Answer
2d movement 1 Answer
How can i Limit the movement of character (x, y axis) on camera view 0 Answers