Jump to content

Using velocity on jump


MoustafaChamli
 Share

Recommended Posts

We're making some motion changes due to the nature of the game, and one of them affects jumping. Right now, it's set up to use a static variable called "JUMPBOOST". We'd like to change that to use the character's current velocity to affect his jump distance (as we have three moving speeds).

 

if (inputInfo->jumpDown && !_model[currentWorld]->GetAirborne())
{
 jump = JUMPFORCE;
 homeBaseMovement->z = homeBaseMovement->z * JUMPBOOST;
 anim = Animation_type::run_jump_rise;
 isJumping = true;
 moveType = Move_type::jumping;
}

 

We've looked into using GetVelocity, but can't seem to figure what's missing to apply it properly.

Link to comment
Share on other sites

You need to get the 'length' of their velocity, that will tell you how fast they are moving. You could then multiply JUMPBOOST by that value, but you should probably limit the multiplier to a certain range.

 

I don't know how you do it in C but Lua is easy.

local Velocity = ent:GetVelocity()
local Speed = Velocity:GetLength()
local JumpPower = JUMPBOOST*Speed; --todo: if Speed is 0, what will you do?

  • Upvote 1
Link to comment
Share on other sites

I think gamecreator is on to something. If I use this:

 

float Velocity = _model[currentWorld]->GetVelocity().z;

 

It seems to work, up to a point. When we reach maximum speed, the character actually jumps backwards!

 

If I try to compile with the following, though:

float Velocity = _model[currentWorld]->GetVelocity().z;
float Speed = Velocity->Length();

 

It returns that the base operand of '->' (on the second line) is not a pointer.

Link to comment
Share on other sites

as we have three moving speeds

 

I was thinking if you have 3 moving speeds and know those speeds and what speed a character is in you can just hardcode the jump boost based on those 3 speeds. speed 1 = 5 boost, speed 2 = 7 boost, speed 3 = 10 boost or something.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...