- Home /
Question by
secondry2 · Jul 20, 2013 at 06:48 AM ·
gameobjectlocationof
Failing to detect X,Y,Z Locations of GameObject
Hi guys!
Ive got this code, thats suppose to move a lantern toward the player and down to imitate a running effect, once it reaches a certain point, its suppose to stop which it is failing to do. (I will also add functionality for it to bob once i get this simple mechanic down pat)
Thanks!
Script:
var posZ = -0.5948148;
var posY = -0.6899948;
private var moveSpeed = 0.1;
private var orgSpeed = 0.1;
var lantern : Transform;
function Update () {
if ( Input.GetKey(KeyCode.LeftShift) ) {
if (lantern.position.z >= posZ && lantern.position.y <= posY) {
moveSpeed = 0;
Debug.Log("STOPPED");
} else {
lantern.position.z += moveSpeed * Time.deltaTime;
lantern.position.y -= moveSpeed * Time.deltaTime;
}
}
}
Comment
You are using global positions for your movement. Are you sure you're not thinking in local space?
Your answer
Follow this Question
Related Questions
Is gameObject present at coordinates (x,y,z)? 1 Answer
Instantiating from a list of gameobjects randomly, with different positions for each gameobject... 0 Answers
What is wrong with this code? (Solved) 0 Answers
Relocate GameObject when location is triggered 0 Answers
How can i spawn a prefab at an empty game object? C# 3 Answers