Jump to content

Character Controller's Jump Height Bugged


Recommended Posts

When the character controller jumps on a flat surface or up hill, jumps seems to be ok but when it jumps downhill, the jumps become smaller and smaller the steeper the hill is. Was visible in this demo as well:

www.leadwerks.com/werkspace/topic/15913-my-first-demo/

 

Relevant code, just in case I'm doing something wrong:

 

bool App::Loop()

{

float startheight, maxheight;

 

if(window->Closed() || window->KeyDown(Key::Escape)) return false;

 

float move = (window->KeyDown(Key::Up) - window->KeyDown(Key::Down)) * 6;

float strafe = (window->KeyDown(Key::Right) - window->KeyDown(Key::Left)) * 6;

float jump = window->KeyDown(Key::S) * 10;

if(!player->GetAirborne())

{

if(jump>0)

{

startheight = player->GetPosition().y;

maxheight = startheight;

}

}

else

{

jump = 0;

if (player->GetPosition().y > maxheight) maxheight = player->GetPosition().y;

}

player->SetInput(0, move, strafe, jump);

 

camera->SetPosition(player->GetPosition(true), true);

camera->Move(0, 0, -10);

 

Time::Update();

world->Update();

world->Render();

 

context->SetBlendMode(Blend::Alpha);

context->SetColor(1.0f, 1, 1);

context->DrawText(String(maxheight-startheight), 10, 10);

context->SetBlendMode(Blend::Solid);

 

context->Sync();

 

return true;

}

 

The uphill jump height actually also gets just a touch bigger the steeper the hill but it's not anywhere as drastic.

Link to comment
Share on other sites

This could be considered correct behavior. If your velocity is negative then jumping would result in a lower velocity than if you are standing still.

 

However, it may make more sense to add the jump velocity to the velocity of the object the character is standing on. That way if you are in a falling elevator, your jump will still be relative to the ground.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I totally get that it's a balancing act between what's physically right and what feels and looks natural. But right now the height issue is very extreme and unnatural for those who have played any sort of jumping games.

 

It literally does something like this. The same distance across but you can't make a jump because you're running on a slope.

 

post-368-0-79135300-1490913197_thumb.jpg

 

It sounds like your solution above may fix this though.

  • Upvote 1
Link to comment
Share on other sites

Ha, makes sense. Since you are pushing off against a stationary object, it makes sense the jump velocity would be the same.

 

Although if you were running downhill, I bet the second image is what would actually happen. :D

 

I agree with you and will see if I can change this behavior.

  • Upvote 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Have you thought about using SetVelocity to set the character's vertical velocity to zero when they jump?

 

Vec3 v = player->GetVelocity()

v.y=0

player->SetVelocity(v)

  • Upvote 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Have you thought about using SetVelocity to set the character's vertical velocity to zero when they jump?

 

Vec3 v = player->GetVelocity()

v.y=0

player->SetVelocity(v)

 

This works but the jump is still not high enough. The y velocity is negative on a downward sloped jump. The following seems to work but note I didn't test it very much...

 

local tmp = self.entity:GetVelocity()

if tmp.y < 0 then

tmp.y = math.abs(tmp.y) --compensate for negative velocity

self.entity:SetVelocity(tmp)

end

  • Upvote 1

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

Have you thought about using SetVelocity to set the character's vertical velocity to zero when they jump?

Good thought. The height from a flat jump remains the same but the sloped jump improved from 5.77 to 8.71. I'd love to see it get even closer to the full height (ideally the whole thing). Here's what the video looks like now:

 

Link to comment
Share on other sites

Good thought. The height from a flat jump remains the same but the sloped jump improved from 5.77 to 8.71. I'd love to see it get even closer to the full height (ideally the whole thing). Here's what the video looks like now:

 

My solution didn't work for you?

  • Upvote 1

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

  • 2 weeks later...

Worth noting that the one problem with the above solution is that when a character lands, it has negative velocity for a frame. As such, if you hold down the jump button, it will jump higher and higher (and then fall through the ground with enough velocity). This isn't an issue for me because I don't plan on allowing this jump (you can't hold jump and keep jumping) but I have to keep this issue in mind.

 

I'm hoping Josh still intends to fix the character controller so we don't keep coming up against unexpected exploits.

Link to comment
Share on other sites

  • 1 year later...
  • Admin locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...