Comparing 2 positions need help
here is the code from update function:
if(canMoveUp == true)
transform.Translate(Vector3.up * (verticalSpeed * Time.deltaTime));
//UpButton
if(upButtonClicked == true)
{
if(this.transform.position.y > playerPosition.transform.position.y+4.0f)
{
canMove = true;
verticalSpeed /=3;
upButtonClicked = false;
}
}
and other function:
function GoForward()
{
// if(canMove == true)
// this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y +4, this.gameObject.transform.position.z);
playerPosition.transform.position = this.transform.position;
upButtonClicked = true;
canMove = false;
verticalSpeed *=3;
}
im trying to make my player to go forward with fasten speed until it reaches the position i want ( +4 on y) why isnt the if statement not working in update function?
Comment
Hi,
I haven't read your entire question but as far as I understand, Can't we achieve the same with the Vector3.Distance ( currentPos, tagertPos)<0.05f
( 0.05 is the $$anonymous$$imum delta distance from which you can justify that, it is okay ) Sorry if I'm wrong ..
nah its not working :/ in my code im taking the position when forward button is clicked and when the player passes like lets say 4 more units on y axis to go to regular speed