- Home /
Question by
SirBoboHobo · Mar 29, 2015 at 06:53 AM ·
updatedistance
calculating vertical distance
i want to calculate the distance the player starts at and it current location on the y axis every Update() to count the score. how do i do that?
Comment
Best Answer
Answer by JedBeryll · Mar 29, 2015 at 09:10 AM
Save the starting y as a float, then subtract from player.transform.position.y: private float groundLevel;
public GameObject player;
private float startHeight;
private float currentHeight;
void Start(){
startHeight = player.transform.position.y;
}
void Update(){
currentHeight = player.transform.position.y - startHeight;
}
assuming you write in c#
Your answer
Follow this Question
Related Questions
How to increment the number by 1's to get distance traveled? 0 Answers
iOS Lag From Updating Score 0 Answers
Linecast not returning distance 2 Answers
My look at script not working? 0 Answers
I have been struggling with a GUI window with table data for over a week now. What am I doing wrong? 1 Answer