Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jseb #26

Closed
wants to merge 14 commits into from
Closed

Jseb #26

wants to merge 14 commits into from

Conversation

jeangit
Copy link
Contributor

@jeangit jeangit commented Oct 23, 2021

I had an issue when climbing a ladder : i'm using a special group for ladders, which doesn't block player. When the player is on the ladder, gravity is set to zero. This way player can go up and down on the ladder.

But when arrived at the top of the ladder, if the player continues it will hit empty space, and gravity is set again to normal value. So the player begins to fall. When he hits again the ladder group, the gravity is set to zero again, but the fall continues until the player has reached the ground or a stopping obstacle.

That's why i've added a test for gravity in the computing of the Y velocity.

@britzl
Copy link
Owner

britzl commented Oct 23, 2021

I'm not convinced that this is the best way to approach this problem. There are cases when gravity is 0 and you still want vertical movement, perhaps in a sci-fi game which switches between a simulated gravity and no gravity. I would recommend that you set vertical velocity to 0 on the first frame when you detect a collision with the ladder.

@jeangit
Copy link
Contributor Author

jeangit commented Oct 24, 2021

I think that wouldn't prevent vertical movements, but only unwanted fall.
In a space game, nobody hear you scream when you fall, because you never fall (unless these is artificial gravity). But that won't prevent the player to move up and down.

The issue i've encountered is when climbing a bit above the top of a ladder:

  1. The gravity is restored to its previous value.
  2. Void space is detected by the engine (no blocking tile under the player)
  3. The player begins to fall.
  4. He crosses the ladder again and his gravity is set to zero again.
  5. But it continues to slowly falling (with the initial velocity, which is very low), due to the velocity computing.

May be there is a better solution, but honestly i have searched two days before modifying the engine.
I do agree it would be far better to solve this in my own code.

@britzl
Copy link
Owner

britzl commented Oct 25, 2021

I did an update on the master branch and added an example of ladders to the Grotto Escape sample. Please have a look and let me know what you think!

@jeangit
Copy link
Contributor Author

jeangit commented Oct 25, 2021

Thank for for having took time to look this issue.

Ok i've looked the new sample:

- player cannot go beyond the top of the ladder or he falls.
- the ladder should be taller than the ground, otherwise it could be difficult for the player to leave it before falling.

+ the player can stop his fall when falling from a ladder, by moving up.
+ or - (depends of gameplay wanted) the player falls when he walks on the top of a ladder.

So IMHO the advantages and drawback are balanced.
As you doesn't seem eager to include my PR (no problem) i will keep it in my branch as i prefer it for my gameplay.

Just a question,about the change you've done in platypus.lua :

- if collide_down and result.normal.y > 0.7 and platypus.velocity.y < 0 and result.fraction < 1 then
+ if collide_down and result.normal.y > 0.7 and platypus.velocity.y <= 0 and result.fraction < 1 then
    if not state.ground_contact then
        state.ground_contact = true

why replacing < 0 with <= 0 ?

@jeangit jeangit closed this Oct 25, 2021
@britzl
Copy link
Owner

britzl commented Oct 26, 2021

why replacing < 0 with <= 0 ?

I set the velocity to 0 when climbing and if you climb down and reach the ground it is important that ground contact is detect even when the velocity is 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants