- Home /
Joystick move Left Right and down, plus rotation.
I want my player to move left and right + a rotation via a joystick or touchscreen object. I want the player to move upwards on its own vertical axis automatically, but slow down and maybe stop moving when I swipe the joystick or touchscreen object down (so I vertically move the joystick down). In my game, I want the player only to be able to move upwards and not be able to go backwards (down on vertical) so the rotation on the player must be limited to a degree, otherwise the player is able to rotate back because the player should always move at least slightly upwards on its own vertical axis. think of the player as a spaceship so there is no gravity.
this is what I have now, but first, what are the problems? -I can rotate all the way back, so I can go backwards. ( I only want to at least go slightly upwards on the vertical axis). - the plane sprite I use jitters when I make a turn, the z rotation is frozen if you were wondering. -I can't slow the plane down at a public rate of speed, with this same joystick, so I want to be able to move Left, Right and down with the joystick.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.CrossPlatformInput; public class AirPlane : MonoBehaviour { [SerializeField] float moveSpeed = 15f; [SerializeField] float angularSpeed = 2f; float rotationX; Rigidbody2D rb;
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
rotationX = CrossPlatformInputManager.GetAxis("Horizontal");
transform.Rotate(0, 0, rotationX * angularSpeed);
}
void FixedUpdate()
{
rb.velocity = transform.up * moveSpeed;
}
}
I would really appreciate your help if you could take the time to help me out.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Rotate the weapon sprite with a joystick 0 Answers
Make movement of an object independant. 1 Answer
How to control a 2d character in an top-down android game with the standard joystick? 1 Answer
How to smoothly rotate object in direction of analog joystick? 1 Answer