- Home /
Random Teleports With Set Coorodinates
//this is the code that i am using for a 2d plat former. When i run it some times when my character jumps or moves it changes the x coordinate seemingly randomly. Do you know what is happening and can i fix it????
var zValue : float;
function Update () {
if( transform.position.z < zValue)
{
transform.position = Vector3(0,0,zValue);
}
if( transform.position.z > zValue)
{
transform.position = Vector3(0,0,zValue);
}
Nothing here will change your 'x' value. Something else could be changing the 'x' value, and this code could be resetting it back to zero. What are you using to move your character? Character conroller? Rigidbody.AddForce()? $$anonymous$$anipulating the Transform?
Answer by bubzy · Jun 10, 2013 at 06:33 AM
var zValue : float;
function Update () {
if( transform.position.z < zValue)
{
transform.position = Vector3(transform.position.x,transform.position.y,zValue);
}
if( transform.position.z > zValue)
{
transform.position = Vector3(transform.position.x,transform.position.y,zValue);
}
this will keep the existing x and y values of your character while modifying the z position.
oh... and why are you using the z axis on a 2d platformer? :D
Your answer
Follow this Question
Related Questions
Problem getting players position. 0 Answers
counting seconds that character is idle. 1 Answer
I have a movement script, but how can i make it so i can move half the speed while in the air. 0 Answers
Converting from moving local space to world space 0 Answers
Basic Movement on a Plane without Character Controller 2 Answers