- Home /
How to know the speed of my FPS controller?
Hi all people, i need help with my FPS game, the question is this:
How to know the speed in real time of my FPS controller?
In need this help to make the sound steps for my player.
Greetings all people and sorry for my bad english.
I show my game in some screenshots i will hope you like the game. Nextly in Kongregate:
Cool lookin game man - but I dont totally understand the question? are you using the default FPS controller that comes with unity? Did you make your own? I think the one in unity has a setting to change the speed, so I guess you could say that your speed is that setting if thats what your meaning...try and rephrase the question a little
Answer by aldonaletto · Feb 11, 2012 at 05:39 PM
If you are using the CharacterController, it's better to measure the velocity in Update:
private var lastPos: Vector3; private var curVel: float; // shows the current velocity
function Start(){ lastPos = transform.position; }
function Update(){ var displacement = transform.position - lastPos; lastPos = transform.position; curVel = displacement.magnitude / Time.deltaTime; } If you want a more smooth velocity indicator, use Lerp to filter it - replace the curVel assignment with this line:
curVel = Mathf.Lerp(curVel, displacement.magnitude/Time.deltaTime, 10f*Time.deltaTime);
The value 10f controls the smoothness: low values make the velocity too slow and smooth, and higher values reduce the smoothness and make curVel follow the actual velocity more quickly.
Your answer
Follow this Question
Related Questions
How do I make the default fps character controller not stick to the mesh it is standing on? 0 Answers
Sprint and Crouch problem! 1 Answer
Switching to the player camera 1 Answer
Why won't my rigidbody fps controller move? 1 Answer
How can I get a responsive rigidbody FPS controller without acceleration that reacts to forces? 2 Answers