Goal: Create a simple platformer. Simple = direct movement with same velocity always.
Must use Non Kinematic RigidBody. Why ? Kinematic ones aren’t affected by collisions and pass through walls. Dont want to use CharacterController.
Approach 1: The Suggested Unity Way:
_rigidbody.AddForce(direction, ForceMode.VelocityChange);
Problem a: Requires 1-2 seconds to build towards max velocity. My goal is to obtain max velocity in 0 seconds time, and remain unchanged while button is pressed. For a platformer game this means that the player will fail to dodge bullets = gameover. Reversing move direction takes 4 seconds time, this is hopeless…
Problem b: takes 5-6 sec time for player to stop moving (sliding on ice effect). This causes the player to fall of the ledge = gameover.
Approach 2: Set Velocity Directly:
_rigidbody.velocity = direction;
Doesn’t suffer from A or B. This is the perfect controller for my needs. Exactly what i want.
Questions:
-
is there a hidden gotcha i need to care? According to Unity:
In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour. Don’t set the velocity of an object every physics step, this will lead to unrealistic physics simulation.
Unity not only treats me as a “noob”, but forbids me to use this approach without specifying what bad is gonna happen. i just did “Bad case” and no nuclear factories exploded, I was going to manually simulate gravity, friction, and external forces applied to player anyway. What should i watch for? Will it be slow?
- Does interpolation mode have any effect if i use such “control”. If not i can set it to None to save Cpu.