
Working on getting player falling and object falling to feel right.
For player falling, this is the code I’m using:
1 2 3 4 5 | if (GetComponent<Rigidbody>().velocity.sqrMagnitude < terminalSpeed * terminalSpeed) { gravityVelocityChange += gravity * myNormal * -1 * Time.deltaTime; GetComponent<Rigidbody>().AddForce(gravityVelocityChange, ForceMode.Acceleration); } |
As long as the player’s falling speed is less then the terminal speed I’ve set (70), the acceleration will be applied to the player.
ForceMode.Acceleration applies a continuous acceleration to the rigidbody, regardless of mass.
All in all, this feels pretty good. When the player initially jumps off a ledge, the fall speed is slow, and then the player accelerates and picks up speed, until the player is traveling at terminal velocity. More or less what you’d expect.
Now, with boxes, it’d be natural to think that it would just fall at the same speed as the player.
However, the problem for me is that in RELATIVITY, when the player switches to another wall while carrying a box, I need that box to drop and fall all the way to the floor. I do that by having the player drop the box turning the rotation, and not switching off the gravity for the box until the player has completely rotated onto the new surface.
When using ForceMode.Acceleration, it’s a little too slow. I can tweak the gravity value to make it faster.
Or I can switch to using ForceMode.Velocity.
The problem with both these solutions, however, is that if the player is falling while carrying the box, and lets go of the box, then the box will fly away.
In Portal, this doesn’t happen – the box actually falls at the same speed as the player, if you let go of it mid-flight.
The thing is, this isn’t actually game-breaking. The important thing is that the player can carry the box while falling, and this already works. It does bother me though.