Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Dec 16, 2012 7:01 am 
Offline

Joined: Sun Dec 16, 2012 6:52 am
Posts: 1
Currently, I am using a btHeightfield shape to define terrain within my game. It works well, provides the appropriate collision.

However, the characters slide when the slope of the terrain isn't zero. Meaning, when you walk down a gentle hill, gravity still takes place and pulls the character down the gentle hill. I'd like to change this so the slopes don't cause the character to slide, rather just stick to the terrain.

What properties should I look at and try?

I'm using a capsule shape and a btKinematicController and Action for my characters.
I'm using a btHeightfield shape and btRigidBody.

I've attempted to set the Friction of both to one, but it seems to be ineffective.

[SOLVED]

The issue deals with the calculation of the vertical velocity. If you want your character to stick onto slopes and what not (as in, not slide down gradual slopes) then subclass the KinematicController, override the playerStep method, and add the following

Code:

    if (!(m_wasOnGround && m_walkDirection.isZero()))
    {
        m_verticalVelocity -= m_gravity * dt;
        if(m_verticalVelocity > 0.0 && m_verticalVelocity > m_jumpSpeed)
        {
            m_verticalVelocity = m_jumpSpeed;
        }
        if(m_verticalVelocity < 0.0 && btFabs(m_verticalVelocity) > btFabs(m_fallSpeed))
        {
            m_verticalVelocity = -btFabs(m_fallSpeed);
        }
        m_verticalOffset = m_verticalVelocity * dt;
    }



The following code will make the character abide by the normal laws of gravity when the player is moving, but when the player is stationary the player will not move at all.

Note that this code worked for generally every case with my playpen, but it might not be optimal for other solutions. I do not know how this responds to such actions as jumping atop static objects, moving platforms, etc.


Top
 Profile  
 
PostPosted: Wed Mar 06, 2013 11:33 pm 
Offline

Joined: Tue May 01, 2012 10:42 am
Posts: 39
Thanks for posting this, I'm also going to use the same setup, so now I don't have to figure that out anymore :) thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group