Hellooo
How would I go about writing a C# code to control a spaceship that turns with the mouse? The code I’m using kinda works but as soon as I attach the camera to the ship it goes heywire. And it doesn’t really turn properly in the 1st place.
Im not really aiming for realism I just need to be able to accelerate and boost and have the speed drop when not pressing the forward key. Many Thanks!
using UnityEngine;
using System.Collections;
public class FlightScript : MonoBehaviour {
public float AmbientSpeed = 100.0f;
public float RotationSpeed = 100.0f;
private float rSpeed = 1.0f;
private Vector3 MousePosition;
public float TurningSpeed = 100;
Vector3 LookAtPos;
Vector3 SmoothedLookAtPos;
public float ForwardSpeed = 100;
void Update()
{
//Look At the Mouse
LookAtPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 100));
SmoothedLookAtPos = Vector3.Lerp(SmoothedLookAtPos, LookAtPos, Time.deltaTime * 5);
transform.LookAt(SmoothedLookAtPos);
//Move forward (you could use a Rigidbody)
}
}