Restricting character climbing

My physics knowledge is rusty… :cry:

Well the RigidbodyFPSWalker may work for me, but…

How can I disable a character from climbing the side of a mountain (like greater than 60 degrees)? With the CharacterController I can set the slope limit which disables running up the mountain, but I need to not allow them to jump up it either. So how could I use the slope limit for a jump (or something similar), or make the character slide down if the incline is too great?

:? , I’m a little slow.

I got it by just getting the normal of a contact point from a collision.

bump, i need this answered too, and the guy above me…i dont understand…could you explain to me (A mind of a 3 year old)

add invisible object with box collider,and your character can’t go thru :wink:

Haha… sorry for the not so detailed explanation… two years ago! :shock: (dusts off code…)

Anyways, here’s some more detailed info as far as code… you’ll also need to attach a collider and such to your object (I’m assuming you can do that)

  1. Created a PlayerRigidbody script with class variables for a slopeLimit, collider, and grounded.
int slopeLimit = 60;
CapsuleCollider capsule;
bool grounded = false;
  1. In the Awake method get the collider (I used a capsule)
void Awake()
{
  capsule = GetComponent(CapsuleCollider);
}
  1. Made a method function TrackGrounded which was passed a Collision.
void TrackGrounded(Collision col)
{
    float minimumHeight = capsule.bounds.min.y + capsule.radius;

    foreach (ConactPoint c in col.contacts)
    {
        if (c.point.y < minimumHeight)
        {
            float slopeAngle = (-c.normal.y + 1.0f) * 100.0f;

            if (slopeAngle < slopeLimit)
            {
                // grounded is used in the FixedUpdate callback
                grounded = true;
            }
        }
    }
}

void FixedUpdate()
{
    if (grounded)
    {
        // Get input status and do player movement...
    }

    // I used custom gravity here
}
  1. Call TrackGrounded on collision callbacks.
void OnCollisionStay(Collision col)
{
    TrackGrounded(col);
}

void OnCollisionEnter(Collision col)
{
    TrackGrounded(col);
}

Might have to play around with some of those values and mess with other things (like if your world can get you stuck between two slopes)… but hope that helps.

edit: oops, added what grounded was for

Lucas

uhh… I can not code worth a damn, so… Im sorry for asking, but could you make a large tutorial, and code for me? im still a noob with this

thnx

sorry for the bump, but please help?

Um… that’s kind of a lot to ask for and currently I don’t have the time to write all that and write your code.

ok, srry, thnx anyway
could you just put the code up, and tell me where to add it someone?

Hi,

I came across this thread when I faced that same problem. I did code a solution you can find useful, and posted it in another thread:
http://forum.unity3d.com/viewtopic.php?t=19263

(just search for the big big post, in the second page)
Should help you code a solution.

G.Otranto