Hi guys,
I am trying to put together a basic vertical scrolling shooter, but I am having trouble. I want to limit the ship to banking to 70 degrees when moving left or right, but can’t figure that out. Heres my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerShip : MonoBehaviour
{
public Rigidbody ship;
public float forwardForce = 1000f;
public float sidewaysForce = 1000f;
public float tilt;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
ship.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("a"))
{
ship.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
ship.rotation = Quaternion.Euler(0.0f, 0.0f, ship.velocity.x * -tilt);
}
if (Input.GetKey("d"))
{
ship.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
ship.rotation = Quaternion.Euler(0.0f, 0.0f, ship.velocity.x * -tilt);
}
}
}