CFrame value returns NaN after applying force

I wanted to make a jumping function. When the player pressed space, the assembly linear velocity of his torso would change and a force would be applied on him. However, I verified that whenever I jumped while staying still, a bug would appear at the output. I didn’t think too much about it until today, when I was changing some code. I had a movement system on air which would basically add a force to the player every time he jumped or pressed any of the movement keys on air. This force was based on the humanoid’s movedirection. However, I tried running this function on renderstepped along with my blockcasts. Now, whenever I press jump, the screen turns black and the output says that the CFrame contains Nan values. Why does this happen and how can I fix it? Thanks

NaN most frequently occurs when dividing a number by zero (which you may know is an operation that doesn’t exist). its likely that when using the movedirection, and the player was initially not moving, that the result is an operation with a cframe position of 0,0,0 which is NaN

1 Like

yeah so it turns out i had this piece of code every time i jumped
movevector.Force = movevector.Force + movevector.Force.Unit * hrp.Velocity.Magnitude / 20
i dont know why it breaks the game but removing it made it work. there is no division by zero so i have no idea why it creates a nan value. could you explain why this may break the game? thanks for helping me out

its because of how movevector.Force.Unit is calculated, the unit vector is divided by its length, which if you’re not moving the movevector is (0,0,0), therefore division by 0

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.