Hey guys i was wondering if you could give me some advice on how to approach this problem i am having. I have some code written , but its not working the way i want it to. I want the player to control an asteroid that they can move around in space. This is the code i have so far which doesnt work.
public var cameraa:Transform;
var smooth:float =5.0f;
var rotationSpeed:float = 10f;
var accnSpeed:float = 10f;
function Update ()
{
var currentRotationX:float = gameObject.transform.rotation.x;
if(Input.GetKey(KeyCode.W)) {
if(currentRotationX < 60 || currentRotationX > 360-60 )
gameObject.rigidbody.AddTorque(-rotationSpeed*Time.deltaTime,0,0);
}
if(Input.GetKey(KeyCode.A)) {
gameObject.rigidbody.AddTorque(0,-rotationSpeed*Time.deltaTime,0);
}
if(Input.GetKey(KeyCode.D)) {
gameObject.rigidbody.AddTorque(0,rotationSpeed*Time.deltaTime,0);
}
if(Input.GetKey(KeyCode.S)) {
if(currentRotationX < 60 || currentRotationX > 360-60)
gameObject.rigidbody.AddTorque(rotationSpeed*Time.deltaTime,0,0);
}
if(Input.GetKey(KeyCode.X)) {
gameObject.rigidbody.AddRelativeForce(Vector3.forward*accnSpeed*Time.deltaTime);
}
}
At the moment the code makes me rotate too far as i hold down WASD, i want to limit the rotation of the asteroid so it doesnt rotate out of control, i also want it to accelerate in the forward direction of my controller direction. Please help help help , been trying to sort this out for weeks, am not getting far at all… im only starting out using unity and cant find any 3rd person controllers for space games that are free.
Thanks guys, would appreciate the helo tons