Dear lövers,
I'm trying to build a simple platformer using Hardon Collider.
I'm stuck on a bug about gravity, ground, and jumps. I know the topic has been discussed a thousand times in the forums, however, after reading a lot of topics and the classic blog posts and tutorial on the subject, I still don't understand how to fix it.
The bug is: when my character stands on the ground, his Y is always changing.
It is almost invisible at 60 FPS, I had to try my game on a slower machine to discover it.
I logged the coordinates of the character to the console so you can reproduce easily.
If you make the game lag, by openning it many times, or on a slower graphic card, you will be able to notice it.
I believe this bug is the cause of another anoying bug: when my character is moving to the right, when reaching the right end of a platform, it gets stuck instead of falling.
More generaly, I need some advice on the right way to code a platformer with HC. My code may be naive. If you know a better way to do please tell me.
My first attemps to fix it was to apply gravity only if the character is not on the ground. But my "on the ground" test being far from perfect, this ended in preventing the character to jump 50% of the times when it should be able to.
Thanks.
Edit: sorry, looks like my attachment was lost in the save draft process...
HC and gravity
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
HC and gravity
Last edited by Kivutar on Sun Dec 09, 2012 10:42 am, edited 1 time in total.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: HC and gravity
Could you upload your .love? We won't be able to help you otherwise.
Help us help you: attach a .love.
Re: HC and gravity
I finally fixed this bug!
For those who are stuck in the same issue with HC:
- Try to not use concave shapes
- Disable gravity when the character is on the ground
- Test if the character is on the ground using HC:ShapesAt
- When resolving collisions, reset Y speed
The following commit shows the changes that fixed this bug:
https://github.com/Kivutar/twinsisters/ ... c2581b0f4e
For those who are stuck in the same issue with HC:
- Try to not use concave shapes
- Disable gravity when the character is on the ground
- Test if the character is on the ground using HC:ShapesAt
- When resolving collisions, reset Y speed
The following commit shows the changes that fixed this bug:
https://github.com/Kivutar/twinsisters/ ... c2581b0f4e
- substitute541
- Party member
- Posts: 484
- Joined: Fri Aug 24, 2012 9:04 am
- Location: Southern Leyte, Visayas, Philippines
- Contact:
Re: HC and gravity
It's actually obvious about the "vibrating on floor" thing. It's also applicable to any type of unpassable surface, as at some point, a shape will go a bit too far into the wall, then get pushed back by the code that prevents intersection.
Code: Select all
Before Collision :
0 ######
Before Correction :
#0####
After Correction, and collision :
0#####
Currently designing themes for WordPress.
Sometimes lurks around the forum.
Sometimes lurks around the forum.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 59 guests