Hey all,
I am working on a spaceship project and I am kinda stuck on something that I think should be fairly simple but can’t figure out a good way to do it. I am creating a Spaceship Game that is on a 2d plane(RigidBody frozen on Y Position) with a 3rd person Orbital Camera.
Since I am only worrying about speed and turning left and right I am just using these two lines for movement;
rb.AddRelativeTorque(new Vector3(0, Input.GetAxis(“Horizontal”) * turnRate * rb.mass, 0));
rb.AddRelativeForce(Vector3.forward * Speed);
Currently this works but it is fairly flat and boring so it would be nice to have a tilt effect, I know I want the ship to tilt 25 (left) or -25 (right) on the Z axis when using the Horizontal Axis, I didnt have any good results doing it to the direct transform so I tried rotating the child object (which holds the actual mesh model of the ship). The below code works slightly, except the model keeps pointing forward instead of turning with the AddRealativeTorque of the parent object.
After a few trying a few different things I figured Id best ask here instead of spinning my wheels for more hours
Would appreciate any assistance!
if (Input.GetAxis("Horizontal") > 0)
{
zAngle = Mathf.Lerp(zAngle, zAngleMin, speedRot * Time.deltaTime);
PlayerShip.transform.rotation = Quaternion.Slerp(PlayerShip.transform.rotation, Quaternion.Euler(0, 0, zAngleMin), speedRot * Time.deltaTime);
}
else if (Input.GetAxis("Horizontal") < 0)
{
zAngle = Mathf.Lerp(zAngle, zAngleMax, speedRot * Time.deltaTime);
PlayerShip.transform.rotation = Quaternion.Slerp(PlayerShip.transform.rotation, Quaternion.Euler(0, 0, zAngleMax), speedRot * Time.deltaTime);
}