|
If I have a MainCamera object with CharacterMotor.js and other related scripts attached, how do I detect how far said MainCamera has fallen? Let's say it fell more than one unit (or whatever the Unity measurement system is called.) How do I detect that?
(comments are locked)
|
|
The easiest way, without seeing more context or code from you, is to set it's starting position in a class variable when the object is created (put the storing of the variable in the Awake() or Start() of a component) then when it has stopped falling use Vector3.Distance() to find the distance between it's starting position and it's final position. If you just want the vertical distance traveled you can simply subtract the startingPosition.y and the finalPosition.y. EDIT based on the additional information below: At about line 265 (inside the UpdateFunction function) there should be a line like the following: Inside that if block is where you would store their starting position/height. Then if you only want to check how far they've fallen once they hit the ground, you would go down to the 'else if' below it that looks like the following: And get it's current grounded position/height, then you can calculate the distance between them. If you want to check how far they've fallen every update until they hit the ground, then you'll need to add your own else if to update things as they fall. Overall an quick and dirty example of that section would be, you will need to add a global Vector3 variable named fallStartPos and a global float variable named fallDistance: I've never really looked at or worked with this particular script before, but from skimming it and based on what you said, this should give you a step in the right direction. I hope it helps! Well, my code is just the CharacterMotor.js that comes with Unity as an example. So what would I do to it to find how far it has just fallen (since it has become ungrounded)?
Dec 22 '11 at 11:51 PM
macweirdo
I've updated my original answer based on your comment and added an example chunk of code that will hopefully help.
Dec 23 '11 at 12:17 AM
Aleron
Thank you! :D
Dec 23 '11 at 03:35 AM
macweirdo
You're welcome. I'm glad it helped. :)
Dec 23 '11 at 04:38 AM
Aleron
(comments are locked)
|
