That would likely indicate the problem is with the code inside those if statements, the statements themselves cant really "store data", it just checks the provided information in ( ) evaluates to true or false, and thats it, if its true the code inside { } gets executed, otherwise that code is skipped - you have narrowed it down to this function causing the issue, I would also see which statement in that function could be causing issues, from your video, it looks to me it may be related to positioning, which could mean your final calculation may be not what you expect it, one of your calculation steps may be adding when it shouldnt or a condition is evaluating to true (or false, when using !), when it maybe shouldnt
#do If statements keep data?
1 messages · Page 1 of 1 (latest)
ok thx for clarifying. yeah i had a problem before when i was trying to do lerp within a coroutine and the best way i can describe it/someone else told me, that it temporarily keeps the T value when you change the target. was just wondering if it would be the same here but now i know.
i also think i narrowed down my problem more. something to do with my Slopechecker to get the angle, but i reduced the raycast length and its somewhat fixing it now. still dont know y it would do that tho
public bool SlopeChecker()
{
if (Physics.Raycast(groundCheck.position, Vector3.down, out slopeHit, 0.25f))
{
slopeAngle = Vector3.Angle(Vector3.up, slopeHit.normal); //Get the angle of the slope
return slopeAngle < controller.slopeLimit && slopeAngle != 0;
}
return false;
}
Ah I see - Lerp is a function, and that function could be caching the value its changing, since it returns a value you can use it in a if-statement or while loop, etc, that might be what they were referring to - thats good you managed to narrow it down further, if a shorter ray "sorta fixes" the problem, it sounds like it could be related to the angle of incline, and where your raycast is firing from, it could be hitting the ramp too early, and as you move up it or jump, your distance from that inclined surface decreases just enough to not touch anymore, only to touch again next frame, possibly
You can visualize your raycasts with the Debug class, or OnGizmos function:
https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDrawGizmos.html
Personally, I like to use a package created by vertxyz: https://github.com/vertxxyz/Vertx.Debugging - though in this specific case, since your just dealing with a raycast, I think Debug.DrawRay should be fine enough, if you end up using more complex casts like maybe a sphereCast or boxCast or something, then this github package becomes a lot more useful imo
Using those debugs to see where your cast is actually landing while your on the ramp and in-air, as well as logging your slope angle, should hopefully help you find out what might be going on
i was trying to do that, but since im raycasting from the bottom center of my player, on higher angled slopes the raycast wont reach so the movement wont work. I also tried to do it with a sphere cast so there always a point of contact when ground and that stops movement completely when im on the ramp
i think i have found the source of the problem which wasnt actually my slope movement but another projectOnplane for just normal WASD movement, i also fixed the jump, so with the raycast i didnt set a distance so it always hits the slope but only do it when im grounded so that fixed the jump problem. but now i found another 2 bugs 😦
Thats the story of programming lol, fix one bug only to lead to 9 more - have you managed to resolve those bugs or investigate further?
yes sir, i think its bug free to my knowledge. except for that 1 i had on the other discord where the vector3 still has those values when you jump causing the player to get an extra boost when jumping
well thx for the help and checking up anyway, especially since i find it difficult to get help with these forum servers