#Jumping while wall grabbing launches the player into the sky

1 messages · Page 1 of 1 (latest)

gloomy kernel
#

Its what it says on the tin. When the player jumps and tries to wall grab the player launches into the sky.

here is the script I'm using for my climbing.

gloomy kernel
#

from a bit of testing it also only seams to happen when the player is not directly up against the wall.

fossil scarab
#

not sure what this is supposed to be doing but using a position as a force vector is a recipe for wacky stuff

fossil scarab
#

Another problem here:

PHYZRB.linearVelocity = new Vector3(PHYZRB.linearVelocity.y, climbspeed , PHYZRB.linearVelocity.z);```
You're plugging y into the x field
fossil scarab
# gloomy kernel what do you mean?

I mean exactly what I said. transform.position as input to AddForce is crazy.

THink about what that means.

If that code runs when you're standing at world 0,0,0, it does nothing.
If that code runs when you're 100 meters away to the east, at (100, 0, 0), it will fling you to the east very quickly

#

basically it's going to do something wildly different depending on where in the universe you are standing when it runs

#

I'm not sure what your intention was with that code, but that can't be right

#

I actually think the second issue with plugging y into the x slot is probably causing the issue you're describing though

gloomy kernel
fossil scarab
#

transform.position ain't it

gloomy kernel
#

ok so how would I do that.
I have working sphere cast would convert that to something.

fossil scarab
#

A simple approach would be to store the hit.point from your spherecast

#

then you can calculate a direction vector from the player to that point with:

Vector3 direction = (spherecastHitPoint - transform.position).normalized;```
#

The vector from A to B is always B - A

gloomy kernel
#

ok thank you I try that out and I'll get back to you.

#

ok I'm sorry I'm still a little new to this how would I store a hit.point?

fossil scarab
#

it's a Vector3

#

it's just a position

gloomy kernel
#

ok how would I do that.

fossil scarab
#

do what

gloomy kernel
#

find the hit.point

fossil scarab
#

It's in the RaycastHit you're getting from the spherecast

gloomy kernel
#

oh lol I'm just over complicating it in my head

#

so this
wallfront = Physics.SphereCast(transform.position, sphereCastRad, Orientation.forward, out fromtWallHit, detectionLedngth, whatIsWall); ?

#

ok ok so something like this
Vector3 direction = (fromtWallHit.point - transform.position).normalized;

gloomy kernel
#

ok I think I'm getting but in the documentation you sent they uses this thing called ray. what is it. it doesn't say anything on it.

fossil scarab
#

you're gettign confused by their example

#

the whole point of the example is to show that you can use hit.point, that's all

#

you can ignore the rest of it

#

in your code you named the RaycastHit something else though

#

so naturally you would use that

gloomy kernel
#

ok so this is correct
Vector3 direction = (fromtWallHit.point - transform.position).normalized;

then i take the "direction"

and use it like this?
fromtWallHit.rigidbody.AddForce(???.direction * moveToLedgeForce, fromtWallHit.point);

#

@fossil scarab

fossil scarab
#

It seems to me like you're still struggling with the basics of C#

#

that's going to make it kinda hard to do this stuff

gloomy kernel
#

no one ever said it would be easy.

#

but still am I on the right track with this?

fossil scarab
#

sort of... but you need to learn how to use variables and call methods.

#

You should look at what parameters AddForce takes as well

gloomy kernel
#

ok so then what would I put in the "???" spot I tried my raycast and that didn't work.

fossil scarab
#

why do you need something in the ??? spot

#

you need to store the position in a variable

#

and then just use the variable

gloomy kernel
#

because it wants something there.

fossil scarab
#
fossil scarab
#

you can't use a variable from another scope like that directly

gloomy kernel
#

I get what a field is I understand methods.
I'm just confused what I need to be doing.

fossil scarab
#

store the data in a field

#

use the field in the other method

gloomy kernel
#

ok let me just start form the top. I'm sorry this is a struggle for me I just can't learn from just reading I need to actually do it.

So this " wallfront = Physics.SphereCast(transform.position, sphereCastRad, Orientation.forward, out fromtWallHit, detectionLedngth, whatIsWall);" is my hit.

I take this wallfront and use it like this
"Vector3 direction = (fromtWallHit.point - transform.position).normalized;"

#

Right?

fossil scarab
#

you should extract the point from it and store that in a variable

#

e.g.

myVariable = fromtWallHit.point;```
#

Then later:

Vector3 direction = (myVariable - transform.position).normalized;```
gloomy kernel
#

thank you.

fossil scarab
#

the variable will need to either be a field, or passed via method parameters to be used in the other method

gloomy kernel
#

ok I got that. So then next I would just mimic this
"hit.rigidbody.AddForceAtPosition(ray.direction * pokeForce, hit.point);" from the docs

fossil scarab
#

Your original code was just using AddForce

gloomy kernel
#

oh no thanks for catching that.

fossil scarab
#

The example code from the docs were just showing you that hit.point exists basically. The entire rest of it is just an example that you don't want to copy unless you happen to be doing exactly what the example was doing

#

which you aren't

gloomy kernel
#

its defiantly smother but still its launching the player up.

gloomy kernel
#

ok heres my code now its still not working right

calm trail
#

in the same manner?

#

and please post your code properly

#

!cod

static bloomBOT
# calm trail !cod
<:error:1413114584763596884> Command not found

There's no command called cod.

calm trail
#

!code

static bloomBOT
gloomy kernel
#

cs

calm trail
#

see the large code blocks section.

gloomy kernel
#
{
    //refrances
    public Transform Orientation;
    public Rigidbody PHYZRB;
    public LayerMask whatIsWall;
    public PlayerMovement pm;

    //climbing
    public float climbspeed;
    public float MaxClimbTime;
    public float climbingTimer;

    public bool climbing;
    public KeyCode ledgeGrab = KeyCode.G;

    public KeyCode wallMoveUp = KeyCode.W;

    //moveto ledge force
    public float moveToLedgeForce;

    //Wall detection
    public float detectionLedngth;
    public float sphereCastRad;
    public float maxWallLoookAngle;
    private float wallLookAngle;

    private RaycastHit fromtWallHit;
    public bool wallfront;
    public bool wallleft;
    public bool wallright;
    public bool wallPointHit;
    
    public Vector3 wallHitVar;


    public float wallPointLocation;



    //
    float horizontalInput;
    float verticalInput;




    void Update()
    {
        WallCheck();

        Vector3 direction = (wallHitVar + transform.position).normalized;
        if (Input.GetKeyDown(ledgeGrab) && wallfront == true)
        {
            PHYZRB.AddForce(direction * moveToLedgeForce , ForceMode.Impulse);
            StateMECH();
        }

        else if (!wallfront == true)
        {
            climbing = false;
            return;
        }


        if (climbing && Input.GetKeyDown(wallMoveUp))
        {
            clmbingmovement();
        }
    }

    private void StateMECH()
    {
        //when to start climbing
        if(wallfront && wallLookAngle < maxWallLoookAngle)
        {
            if(!climbing)
            {
                startclimbing();

                //timer
                if(climbingTimer > 0)
                {
                    climbingTimer -= Time.deltaTime;   
                    if(climbingTimer < 0) stopClimbing();
                }

            }
        }

        //state none
        else
#
if(Input.GetKeyDown(ledgeGrab) && climbing)
            {
                PHYZRB.useGravity = true;
                stopClimbing();
            }
                
            //you are HERE!
        }
    }
    private void WallCheck()
    {
        wallfront = Physics.SphereCast(transform.position, sphereCastRad, Orientation.forward, out fromtWallHit, detectionLedngth, whatIsWall);
        
        wallleft = Physics.SphereCast(transform.position, sphereCastRad , -Orientation.right, out fromtWallHit, detectionLedngth, whatIsWall);
        wallright = Physics.SphereCast(transform.position, sphereCastRad , Orientation.right, out fromtWallHit, detectionLedngth, whatIsWall);
        //the madness that is found at 5:15 AM is a madness only I hold.
        wallLookAngle = Vector3.Angle(Orientation.forward, -fromtWallHit.normal);
       
        wallHitVar = fromtWallHit.point; // The point of no return
        //You are here

        if (wallfront == true)
        {
            Debug.Log("HAY I SEE A WALL.");
        }
        if(pm.isGrounded)
        {
            climbingTimer = MaxClimbTime;
        }
    }

    private void startclimbing()
    {
        climbing = true;
    }

    private void clmbingmovement()
    {
        PHYZRB.linearVelocity = new Vector3(PHYZRB.linearVelocity.x, climbspeed , PHYZRB.linearVelocity.z);
        PHYZRB.useGravity = false;
    }

    private void stopClimbing()
    {
        climbing = false;
        PHYZRB.useGravity = true;
    }













    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame

}```
calm trail
#

nope, not how you do it

#

see the Large Code Blocks section.

gloomy kernel
#

ok dose this work

calm trail
#

you didn't save the paste

gloomy kernel
#

its not letting me save it.

#

ok dose this work

calm trail
#

yes

#

now, what's the current issue? is it still the same issue of launching the player up?

gloomy kernel
#

yes thats the main issue

calm trail
#

well, this script only affects the rigidbody in 2 places

#

if you comment one or the other out, do you still get launched?

#

if you do, then the cause isn't in this script - it may be something else that is kinda fighting this one

gloomy kernel
#

what do you mean two places?

#

do you mean the PHYZRB.AddForce(direction * moveToLedgeForce , ForceMode.Impulse);

calm trail
#

yes, that and setting the velocity on line 134

#

i meant to mention them and forgot, mb

gloomy kernel
#

ok so I did disable one and I was still dealing with the issue.

calm trail
#

and what if you disable the other?

gloomy kernel
#

the one at 134

calm trail
#

(and do make sure you're saving & compiling when testing)

calm trail
gloomy kernel
calm trail
#

Vector3 direction = (wallHitVar + transform.position).normalized;
this doesn't seem right

#

a vector from A to B looks like B - A, not B + A

gloomy kernel
#

I tried that but when I did I would move backwards.

ok and when I do the one at line 59 the player dose not move to the wall.

calm trail
#

but do they get launched

#

hey, how exactly is the player getting launched? got a video?

#

I tried that but when I did I would move backwards.
maybe you did A - B instead of B - A

gloomy kernel
#

well they don't get launched but now there is something stranging going on with the spherecast detection.

#

and give me a second I'll get you a video