Game Development Community

Velocity question

by Erik Madison · in Torque Game Engine · 06/11/2003 (2:53 pm) · 2 replies

Player velocity is confusing me. I assumed it meant speed, but now I'm not so sure...

Where it's getting me, is in the below function. First off, I don't understand what exactly this thing is doing. I noticed both run and walk were defined (at least in RW), so I created both animations. Both seem to work in the game, but I cant figure out why. My player usually runs, but will drop to a walk when I'm near a slope. Okay, that's what it should be doing. Except I don't notice any change in the players speed, and since maxspeed is still hardcoded, I didnt think there should be any.
Any of this make sense? :)

// Our feet are on something
// Pick animation that is the best fit for our current velocity.
// Assumes that root is the first animation in the list.
F32 curMax = 0.1;
VectorF vel;
mWorldToObj.mulV(mVelocity,&vel);
for (U32 i = 1; i < PlayerData::NumMoveActionAnims; i++) {
PlayerData::ActionAnimation &anim = mDataBlock->actionList[i];
if (anim.sequence != -1 && anim.speed) {
F32 d = mDot(vel, anim.dir);
if (d > curMax) {
curMax = d;
action = i;
forward = true;
}
else
{

#1
06/11/2003 (3:50 pm)
That is correct, kind of. Velocity is a vector quantity which represents speed and direction. The magnitude (length) of a velocity vector is the speed of an object.

This block of code transforms the velocity vector into object space, then checks to make sure the animation direction and the velocity are going the same way, IE it picks forward run for when you are going forward, backward run when you are moving backward. This block of code here does not at all modify the magnitude of the velocity, the speed.

What I am guessing (GUESSING...GUESSING) is that the velocity vector, on a steep enough incline is down-ish, and the animation associated with this is the walk animation. I don't know off hand the best way of doing what you want to do, but to change the magnitude of a vector you need to first normalize the vector, then scale it by the new length.
#2
06/11/2003 (4:18 pm)
This helps a little bit. All I need to do, is understand this so I can control it better. It seems all of this would be managed easier in an if else, such as if speed > walkspeed and not in water and facing forward, play run.
I also read a few times Joe Maruschak has mentioned the animations speed in the dsq distinguished between the animations chosen. That only confused me more :) Not only do I not see any mention of this in the applicable code, I also don't see a reason/need for such a thing.