I'm messing around in the Source SDK and wanted to add a jetpack for fun. It took me a while to grasp the vector usage but I finally have something that resembles a jetpack. Source code:
[code]bool CGameMovement::CheckJetButton( void )
{
//* if not set to null, player can't leave ground without jumping
SetGroundEntity((CBaseEntity *)NULL);
float upwardThrust = 11.0f;
float fMove = mv->m_flForwardMove;
float sMove = mv->m_flSideMove;
float uMove = mv->m_flUpMove;
if (fMove != 0 || sMove != 0)
upwardThrust = 10.0f;
fMove *= 2.5f;
sMove *= 2.5f;
uMove *= 2.5f;
Vector x, y, z, first, second;
AngleVectors(mv->m_vecViewAngles, &x, &y, &z);
VectorNormalize(x);
VectorNormalize(y);
VectorNormalize(z);
first[0] = x[0] * fMove + y[0] * sMove + z[0] * uMove;
first[1] = x[1] * fMove + y[1] * sMove + z[1] * uMove;
first[2] = x[2] * fMove + y[2] * sMove + z[2] * uMove;
VectorCopy(first, second);
VectorNormalize(second);
mv->m_vecVelocity[0] += second[0];
mv->m_vecVelocity[1] += second[1];
mv->m_vecVelocity[2] += second[2] + upwardThrust;
if (mv->m_vecVelocity[0] > 0 && mv->m_vecVelocity[0] > 1500)
mv->m_vecVelocity[0] = 1500;
else if (mv->m_vecVelocity[0] < 0 && mv->m_vecVelocity[0] < -1500)
mv->m_vecVelocity[0] = -1500;
if (mv->m_vecVelocity[1] > 0 && mv->m_vecVelocity[1] > 1500)
mv->m_vecVelocity[1] = 1500;
else if (mv->m_vecVelocity[1] < 0 && mv->m_vecVelocity[1] < -1500)
mv->m_vecVelocity[1] = -1500;
return true;
}[/code]
Now, I've added a new keybind and in WalkMove where it checks to see if a player has jumped, I added a new check to see if a person presses the new keybind and if so, this is called and they try to jet.
My first question is, is there a better way to implement this? I eventually plan on tying it to a power source such as the suit armor or aux power.
My second question is, how can I make it more responsive? I want to have to over come any momentum gained when trying to change directions but as it stands now, it takes quite a while and effort to start going in the opposite direction you're already moving. Just trying to adjust your course with the moveleft/moveright can be pretty unresponsive when trying to make quick adjustments.
Thanks in advance.
Okay, I found out that the VectorNormalize was numbing the responsiveness of the input. So, I removed that and lowered the value of fMove, sMove and uMove dramatically and it's a lot closer to what I want.
So, I guess my next question is, how do I play a sound while jetpacking and loop it and then cancel it, even in mid play when the jetpack button is released?
[QUOTE=hd!;18061844]
My second question is, how can I make it more responsive? I want to have to over come any momentum gained when trying to change directions but as it stands now, it takes quite a while and effort to start going in the opposite direction you're already moving. Just trying to adjust your course with the moveleft/moveright can be pretty unresponsive when trying to make quick adjustments.
[/QUOTE]
Can't you just set their velocity when they try and change direction, then begin building velocity again?
edit: Didn't read the new post! Sorry.
Sorry, you need to Log In to post a reply to this thread.