GithubHelp home page GithubHelp logo

Comments (2)

mafiesto4 avatar mafiesto4 commented on May 28, 2024

I'm not sure if PhysX lib we use for physics simulation provides such information.

from flaxengine.

buzzdx avatar buzzdx commented on May 28, 2024

If physx doesn't allow for that, could you implement it yourself?

I used this code to implement the sliding behaviour myself (following a youtube guide that is ^^)

`private void HandleSlopeSlidingCapsuleCast()
{
// length needed to hit the ground even when on very steep surface - might need to change if it's not working correctly everyhwere
float tracelength = (75f/2f)+10f;

        if(Physics.CapsuleCast(Actor.Position, 75f, 0f, Vector3.Down, out RayCastHit hit, Quaternion.Euler(Vector3.Zero), tracelength, TerrainCollisionLayer, false))
        {                
            //Debug.Log("Ground detected!");
            //BoundingSphere b;
            //b.Center = hit.Point;
            //b.Radius = 5;
            //DebugDraw.DrawSphere(b, Color.Red, 1f);

            float angle = Vector3.Angle(hit.Normal, Vector3.Up);
            //Debug.Log("Angle of ground: " + angle);                

            if(angle > 45f)
            {
                //Debug.Log("We should slide now!");
                slopeSlideVelocity = Vector3.ProjectOnPlane(new Vector3(0, yVelocity, 0), hit.Normal);                    

                // NOTE: i was looking for a way to make the sliding go faster. just multiplying the velocity 
                //       seems to do the trick just fine ^^
                // UPDATE: multiplaying the Y component led to the char seemingly jumping higher. removing it
                //         got me to the desired effect.
                slopeSlideVelocity.X *= 2;
                slopeSlideVelocity.Z *= 2;
                return;
            }
        }

        // fade out sliding instead of instant stop as long as we have a certain speed. deactivate this part to get instant stop.
        // NOTE: however, this will still result in the char being pushed away from slope he walked onto. 
        if(isSliding)
        {
            slopeSlideVelocity -= slopeSlideVelocity * Time.DeltaTime * 12;
            
            if(slopeSlideVelocity.Length > 50)
            {                    
                return;
            }
            else
            {
                // need this here to one-time after sliding re-enable player input
                MovementProhibited = false;
            }
        }

        if(slopeSlideVelocity != Vector3.Zero)
        {
            slopeSlideVelocity = Vector3.Zero;
            MovementProhibited = false;
        }
    }`

It will remove player control and then slide down a slope that is detected beneath the player. The problem with this is, as you can see from the NOTE in there, if the player just walks onto a slope that would result in sliding, he first walks onto it, then gets pushed back. I think this is because this movement i manually add clashes with the normal movement of the engine?

When set to prevent climbing + force sliding without my custom code, the character would just not step on that slope to begin with. Would it be possible to implement this kind of code on the engine level to prevent that pushback?

Also kind of weird that PhysX would not expose that information, but I don't know much about it so this i just me wondering how other engines with physx do that kind of thing then ^^

from flaxengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.