#Gonna make this a thread thistime Got it

1 messages · Page 1 of 1 (latest)

formal talon
#

e

white bison
#

Does it work if you skip the RotateTowards and just set the rb rotation to finalTargetAngle?

#

For now

formal talon
#

Let me check. I was about to say I changed playerRB.rotation to transform,rotation and i also forgot to set rotationSpeed to * Time.deltaTime

#

its working better but seems laggy now. Will try your suggestion quickly

white bison
#

Get it working correctly first, then apply the smoothing

white bison
#

The problem might be that your SphereCast is not hitting anything when youre going up the high angled slope

formal talon
#

Its responding for sure

white bison
#

Store your ground normal in a private variable instead, and only update it to the ground normal if your SphereCast hits anything (returns true)

formal talon
#

Okay

white bison
formal talon
#

Adding +0.1f to the SphereCast fixed it

white bison
#

Im pretty sure you could just use one SphereCast for this. Just noticed you have two

white bison
formal talon
white bison
#

Btw the GIF filesize is 222 megabytes

formal talon
white bison
#

Probably, I never shared video in discord chat

#

Usually I see mp4

formal talon
#

Ahh

#

Should I be using a raycast for angle instead of spherecast btw

#

Ive got another issue, just rendering the gif its short this time

white bison
#

Use spherecast. A ray can go through a small hole or get missed more easily

formal talon
#

I think because im using a spherecast for this check its makig it worse.

#

Ah okay

#

The issue is upon entering the slope

white bison
#

Just make sure your sphere doesn't start inside another collider because that's what causes it to not detect a hit. Which I think you fixed with adding the 0.1f

formal talon
formal talon
#

whatIsGround

white bison
#

Maybe use two spherecast after all: front paws and back paws

#

And use their average normal with Vector3.Slerp(frontNormal, backNormal, 0.5f) or something

#

Just an idea

formal talon
#

Ohh thats not a bad idea

#

Ill give it a go

#

I gave up on writing in manually the position of the raycasts

#

is using an empty child fine?

#

thats what ive BEEN doing, but wanted to make sure its not bad for performance or something

white bison
#

If the spherecast is overlapping a collider where it starts, it will ignore that collider

#

So if it starts from inside the ground it will not detect anything

formal talon
#

Altough it definately doesnt start inside of the collider 😛

white bison
formal talon
#

I only know this because I once ran this on unity 22 with the physics analyser

formal talon
white bison
#

Physics visualization would really help here, why not use 22?

formal talon
#

Because it churns out around 40 errors per second

#

and it starts to lag unity after maybe 8 minutes and becomes unusable after 12

#

Ive reinstalled it, and even installed 23

#

I COULD give it another try see if it was some weird issue with that environment, I rebuilt it from scratch

white bison
formal talon
#

ohh

formal talon
white bison
#

It's a normal direction so Vector3

formal talon
#

Okay gotcha

#

Then two spherecasts instead

formal talon
#

Alright, doesnt seem to be working still. Its not showing an average for sure. Lemme install that package quickly

#

Decided to just say fk it and upgrade to 23, see if it was just somethign weird in the environment from that project because surely the error wouldnt persist from 2022 to 2023

#

In the mean time this is the script currently.

#
isGrounded = Physics.SphereCast(castMid.transform.position, capsuleRadius, -transform.up, out var hit, playerHeight + 0.1f, whatIsGround); //check if grounded
        Physics.SphereCast(castFront.transform.position, capsuleRadius, Vector3.down, out var getFrontGroundAngle, playerHeight + 0.1f, whatIsGround); //get ground normal vector
        Physics.SphereCast(castBack.transform.position, capsuleRadius, Vector3.down, out var getBackGroundAngle, playerHeight + 0.1f, whatIsGround); //get ground normal vector
        Vector3 frontGroundAngle = getFrontGroundAngle.normal;
        Vector3 backGroundAngle = getFrontGroundAngle.normal;
        Vector3 groundAngle = Vector3.Slerp(frontGroundAngle, backGroundAngle, 0.5f);
        horizontalInput = Input.GetAxisRaw("Horizontal"); //insert Horizontal input
        verticalInput = Input.GetAxisRaw("Vertical"); //insert Vertical input
        if(isGrounded)
        {
            if(horizontalInput > 0 || verticalInput > 0 || horizontalInput < 0 || verticalInput < 0)
            {
                float currentXAngle = playerRB.rotation.x;
                float currentZAngle = playerRB.rotation.z;
                float targetYAngle = Mathf.Atan2(horizontalInput,verticalInput) * Mathf.Rad2Deg + orientation.eulerAngles.y;
                Quaternion qTargetYAngle =  Quaternion.Euler(0,targetYAngle,0);
                Quaternion qTargetGroundAlign = Quaternion.FromToRotation(Vector3.up, groundAngle);
                Quaternion finalTargetAngle = qTargetGroundAlign * qTargetYAngle;
                transform.rotation = finalTargetAngle;

            }
        }
formal talon
#

Update, I forgot to change a variable KEK. Its got a smoother transition, but the weird freezing still happens as in that gif

formal talon
formal talon
#

Fixed I think 🙂

#

Looking not half bad