We’ve been working on a physics platformer game (iO) in Unity 4.6 for a few years now, and it’s released on several platforms. For future upgrades and potentially different platforms, we’re looking into the possibility of upgrading to Unity 5.2. While most stuff worked instantly, we have major issues with the main character of the game: a ball that can change its size in order to influence mass, speed and momentum. The game is created in 3d, but shown in a 2d view, where the player moves along the Z axis.
The player with a rigidbody is reacting totally different to the same script used in Ynity 4.The player object has a nonkinematic rigidbody and a couple of children with their own kinematic rigidbodies. When looking into this issue we found that freezeRotation has changed to localspace with the coming of Unity 5. (In Unity 4 we froze x&y rotation of the player to keep in alignment with z-axis). This caused the ball (player object) being unable to move in Unity 5. We fixed this by removing the yRotFreeze. While the ball is able to move along the correct axis now, it’s much slower and doesn’t behave the same way it used to. Also, the object doesnt move faster anymore when increasing the torque. The behavior of the ball is the most important part of the game, since this influences how you proceed through the levels (with mechanics like wall climbing, speeding up, launching yourself, etc). We can’t find an answer anywhere via Google or the doc reference, so hopefully someone here can help us. Below you can find the code we use for player behavior:
class PlayerClass
{
void FixedUpdate()
{
// Add Gravity
body3d.AddForce(0.0f, -9.81f * Mathf.Pow(body3d.mass, gravityExponent) * gravityScalar, 0.0f); // Get input
torqueInput = input.GetTorqueAxis();
brakeInput = input.GetBrakeAxis(); // Add Force to object
body3d.AddTorque(0, 0, -torqueInput * torque * Mathf.Pow(body3d.mass, forceExponent) * multiplier, ForceMode.Force); // Add breaking force to object
float brakeForce = body3d.angularVelocity.z < 0.0f ? brakeInput : -brakeInput;
body3d.AddTorque(0, 0, brakeForce * Mathf.Pow(body3d.mass, forceExponent) * reverseMultiplier); // Cap the velocity if it passes the maximum.
if (body3d.velocity.sqrMagnitude > maxVelocity * maxVelocity)
{
body3d.velocity = body3d.velocity.normalized * maxVelocity;
}
}
}