- Home /
How to achieve Luftrauser like airplane gameplay in 2.5D
Hi guys, I'm currently trying to make a 2D airplanes game and my goal right now is to achieve the same kind of gameplay you find in the version 1.0 of Luftrauser.
So I have a 3D aircraft model that I need to apply the correct rotations to so that the aircaft behaves like in Luuftrauser. So basically, the plane should always go towards it's forward vector and the horizontal axis will determine the direction we go in.
I have determined that the movement I'm looking for is a simple "add the same amount of degrees on both X-axis and Z-axis"
Although, when I log the transform.rotation.eulerAngles
of my aircraft, I can see X and Z are changed but they don't have the same value.
Here is the code I use for this rotation :
class PlayerController (MonoBehaviour):
public acceleration as single
public handling as single
def FixedUpdate ():
movementHorizontal as single = Input.GetAxis("Horizontal") * handling
movementVertical as single = Input.GetAxis("Vertical") * acceleration
rotationZ as Quaternion = Quaternion.AngleAxis(movementHorizontal, Vector3.right)
rotationX as Quaternion = Quaternion.AngleAxis(movementHorizontal, Vector3.forward)
transform.rotation = rotationZ * rotationX * transform.rotation
I'm not sure what's wrong, the aircraft has a rigidbody and ideally I would like to achieve this rotation with it and not the Transform.
Answer by Skflowne · Apr 05, 2014 at 04:30 AM
So I finally figured it out, turns out having the values of the rotations as class variables helped a lot. Here is the working code if anyone is interested :
class PlayerController (MonoBehaviour):
public acceleration as single
public handling as single
private currentRotationX as single
private currentRotationZ as single
def Start():
currentRotationX = 0.0f
currentRotationZ = 0.0f
def FixedUpdate ():
movementHorizontal as single = Input.GetAxis("Horizontal") * handling
movementVertical as single = Input.GetAxis("Vertical") * acceleration
rigidbody.AddForce(transform.forward * movementVertical, ForceMode.Acceleration)
invertXRotation as bool = false
invertZRotation as bool = (currentRotationX < -180)
currentRotationX = (currentRotationX + (-movementHorizontal if invertXRotation else movementHorizontal)) % 360
currentRotationZ = (currentRotationZ + (-movementHorizontal if invertZRotation else movementHorizontal)) % 360
rotationX as Quaternion = Quaternion.AngleAxis(currentRotationX, Vector3.right)
rotationZ as Quaternion = Quaternion.AngleAxis(currentRotationZ, Vector3.forward)
rotation as Quaternion = rotationX * rotationZ
transform.rotation = rotation
Your answer
Follow this Question
Related Questions
Quaternion Rotation around Local Axis 2 Answers
Rotate Rigidbody to always face a force 0 Answers
Problem with normal snapping and rotations. 1 Answer