#Gonna make this a thread thistime Got it
1 messages · Page 1 of 1 (latest)
Does it work if you skip the RotateTowards and just set the rb rotation to finalTargetAngle?
For now
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
Get it working correctly first, then apply the smoothing
Same issue
The problem might be that your SphereCast is not hitting anything when youre going up the high angled slope
Its responding for sure
Store your ground normal in a private variable instead, and only update it to the ground normal if your SphereCast hits anything (returns true)
What are you logging here
oh crap, thats the other normal check. ignore that
Adding +0.1f to the SphereCast fixed it
Im pretty sure you could just use one SphereCast for this. Just noticed you have two
Is the issue in that GIF fixed?
Yes
Btw the GIF filesize is 222 megabytes
Is there a better way to do this? xD
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
Use spherecast. A ray can go through a small hole or get missed more easily
I think because im using a spherecast for this check its makig it worse.
Ah okay
The issue is upon entering the slope
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
It has the player ignored in layermask
whatIsGround
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
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
That has nothing to do with what I said
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
OH gotcha
Altough it definately doesnt start inside of the collider 😛
Also this is pretty important ^
Don't update your ground normal with hit normals if they dont hit anything. Otherwise you are using the default value from the RaycastHit.normal which is zero or something
I only know this because I once ran this on unity 22 with the physics analyser
Ill do that first before I forget
Physics visualization would really help here, why not use 22?
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
Package from vertx that allows you to show physics stuff:
https://github.com/vertxxyz/Vertx.Debugging
ohh
Sorry, what variable type do you store this as?
It's a normal direction so Vector3
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;
}
}
Update, I forgot to change a variable KEK. Its got a smoother transition, but the weird freezing still happens as in that gif
This is happening currently