system
February 11, 2012, 5:26pm
1
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:
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.