Hello,
I have been experimenting with 3D movement since I am a beginner and I have found something weird.
If I don’t "implement’ the rb.AddForce() line, the calculation goes good, but as soon as I include that line of code, the calculation messes up horribly.
It also doesn’t matter if I put the Calc() in Update or FixedUpdate, the result is the same.
This isn’t intended to start an argument but of course it is a code error.
The first rule of software development is “it is probably your fault”. It could be due to a misunderstanding of how things work but one can’t suspect that nobody has been able to AddForce to a rigid body.
There is nothing in the code you’ve shown that reveals what the values are (like logging the values as a sanity check). I don’t know in what order your AddForce calculation is being executed but I never leave equations to chance. Parentheses to insure order are free to use.
Those two lines don’t make sense as your moveInput is supposed to be in local space but then you subtract a world space vector, namely the velocity of the rigidbody. So you’re mixing coordinate spaces here. Also AddForce has an optional “Space” argument where you can select if you want to apply a world space or local space force. You can use AddRelativeForce to apply a local space force.
So you have to decide if your moveCalc should be in local space or world space. Everything else in your code seems to imply that you intend to use local space except for the velocity subtraction. So either transform the velocity into local space (InverseTransformDirection) or calculate your moveCalc and accel stuff in worldspace.
I think you may be confusing the AddForce arguments with transform.Translate’s arguments. AddForce doesn’t have a Space argument. Although we can use the underused AddRelativeForce if we want to move a rigidbody in local space.