Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

c++ - Avoid ground collision with Bullet

I'm trying to use Bullet physic engine to create a 3D world.

I've got my character with a Capsule shape on his body and my ground his made of some static blocs stick together, here is a schema to illustrate my words: enter image description here

The problem is present when my character run from one block to another: Bullet detect a collision and my character start to jump a little bit on y-axis.

How can I avoid the problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What I did to overcome this issue is the following:

Instead of have the capsule slide on the ground, I had a dynamic capsule ride on top of a spring. I implemented the spring as several ray casts originating from bottom of the capsule. The length of the spring was like half a meter or less and it would pull and push the capsule to and from the ground. The grip/pull is important so the character wouldn't jump unexpectedly. The springs stiffness controls how much bobbing you have.

This had the following effects

  • No unwanted collision with edge of geometry on the floor, since the capsule floats
  • Walking up stairs and slopes implemented implicitly. The spring would just "step" onto the stair's step and push the character capsule up.
  • Implementation of jumping was just matter of releasing the grip on the ground the spring had and giving the body an impulse.
  • A landing character after a jump or fall automatically displayed "knee-bending" as you would expect
  • Pleasant smoothing of vertical movements in general. Like on elevator platforms etc.
  • Due to the grip/pull to the ground, even when running downhill the character would not start to "fly" as you experience in some games (I find that annoying typically).
  • Ducking character = decrease the length of the spring and/or the capsule.
  • Sliding downhill? You can fully control it by checking the angles of the floor area the ray cast of the spring hit.

I had to play around a lot with the stiffness of the spring, the length of the spring, the length of the grip etc. but in the end I was very happy about how simple yet well this worked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...