Vehicle direction clamp jitter
by DNADMG · in Torque Game Engine · 03/15/2006 (9:27 am) · 5 replies
Hello peoples.. another question/insight request..
I almost have my vehicle direction clamp working on my race track.. I am making a racing game, and am using a reference vector to determine the forward direction of the track(this game is for little kids so I need to restrict their movement to being in the forward direction only, for simplicity sake). So what I did was add a clamp inside the vehicle::setPosition() function in vehicle.cc
// mTrigger is a boolean that I exposed to be set in script when I want this clamp to be turned on
if (mTriggerON)
{
if ((rot.z ) < (mTrigQuatz - 0.17f))
{
rot.z = mTrigQuatz - 0.17f;
rot.w = mTrigQuatw - 0.15f;
}
else if ((rot.z ) > (mTrigQuatz + 0.17f))
{
rot.z = mTrigQuatz + 0.17f;
rot.w = mTrigQuatw + 0.15f;
}
}
to clarify how this works.. I have a trigger box around my track defining change in direction. I use the trigger.rotation and convert the deg->rad, then convert the entire vector to a Quaternion value. This quat is sent to the engine in the form of mTrigQuatx, mTrigQuaty .. etc.. so everytime that the position is updated (and if the trigger has been tripped), it checks to see if our current car rotation is wider than it should be, and if so I stop it at that right or left bound. The 0.17, and 0.15 values are determined by visually comparing my vehicle quat, with the trigger quat and looking at the differences in their rotations, and 0.17 and 0.15 were the max difference that looked to be sufficient to keep the vehicle in the forward direction.
ok so to my current problem. This clamp makes it choppy when it is implemented. The vehicle runs smoothly when it is safely within my bounds, but when I turn hard right/left the car's rotation is restricted, but I get a jumpy movement. Any ideas on how I can smooth this out? Basically I want the car to just stop rotating left/right when it gets to that boundary.
thanks for the help.
-aryn
I almost have my vehicle direction clamp working on my race track.. I am making a racing game, and am using a reference vector to determine the forward direction of the track(this game is for little kids so I need to restrict their movement to being in the forward direction only, for simplicity sake). So what I did was add a clamp inside the vehicle::setPosition() function in vehicle.cc
// mTrigger is a boolean that I exposed to be set in script when I want this clamp to be turned on
if (mTriggerON)
{
if ((rot.z ) < (mTrigQuatz - 0.17f))
{
rot.z = mTrigQuatz - 0.17f;
rot.w = mTrigQuatw - 0.15f;
}
else if ((rot.z ) > (mTrigQuatz + 0.17f))
{
rot.z = mTrigQuatz + 0.17f;
rot.w = mTrigQuatw + 0.15f;
}
}
to clarify how this works.. I have a trigger box around my track defining change in direction. I use the trigger.rotation and convert the deg->rad, then convert the entire vector to a Quaternion value. This quat is sent to the engine in the form of mTrigQuatx, mTrigQuaty .. etc.. so everytime that the position is updated (and if the trigger has been tripped), it checks to see if our current car rotation is wider than it should be, and if so I stop it at that right or left bound. The 0.17, and 0.15 values are determined by visually comparing my vehicle quat, with the trigger quat and looking at the differences in their rotations, and 0.17 and 0.15 were the max difference that looked to be sufficient to keep the vehicle in the forward direction.
ok so to my current problem. This clamp makes it choppy when it is implemented. The vehicle runs smoothly when it is safely within my bounds, but when I turn hard right/left the car's rotation is restricted, but I get a jumpy movement. Any ideas on how I can smooth this out? Basically I want the car to just stop rotating left/right when it gets to that boundary.
thanks for the help.
-aryn
About the author
#2
03/15/2006 (10:09 am)
Are you syncronizing your mTrigQuat variables between the server and client? I added a variable to dynamically constrain the players freelook range, and got choppiness because I muffed up and it was only being set on the server and not the client, so the client fights against the server settings and you get the bugginess.
#3
03/15/2006 (10:19 am)
Hmm.. I put that code into the setPosition function thinking that would be the last place that the position would get set, by either the client or the server..
#4
03/15/2006 (10:25 am)
Could it be that my Render position and the set position rotation vectors are different? ... causeing interference.. i am checking ...
#5
03/15/2006 (10:31 am)
That was it! .. I just applied that same clamp to the render position and it smoothed it out.. on the right side only though.. I have to see whats going on with my left one.. but halfway there ..
Associate Scott Burns
GG Alumni