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();
}
// 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.