- Home /
Object doesn't turn at the desired rate
Hi there!
I'm doing this script to control a ship in a 3D environment. However, when I try to change the speed rotation, the rotating speed is just to slow, and even if I make the rotation happen at a 360º per second, it rotates at the same speed as if I had set it at 90º per second.
Also, when I change the speed direction, instead of going forward on it's own Z axis, the ship conserves its direction.
Here's the code:
//Horizontal Axis control ship left-right direction, Vertical Axis control top-bottom direction, ShipSpeed Axis controls the speed of the ship.
//these are to be replaced through stored variables (maybe in a XML file)
var agility : float = 90.0; //Agility of the craft, soon to be controled through stored variables. In degrees per second.
var speed : float = 10.0; //Speed of the craft, soon to be controled through stored variables
function Start () {
}
function Update () {
//Movement
//obtain movement variables
var vert = Input.GetAxis("Vertical") * agility * Time.deltaTime;
var horz = Input.GetAxis("Horizontal") * agility * Time.deltaTime;
var fwd = Input.GetAxis("ShipSpeed") * Vector3.forward * speed;
//here we rotate the ship
transform.Rotate(vert,horz,0);
//give speed to the ship
rigidbody.AddRelativeForce(fwd);
}
So how can I fix those issues?
Thanks in advance for the anwers.
Answer by Artifactx · Jul 24, 2012 at 05:42 PM
have you tried to calculate your speed like this:
public var speed : float = 10.0;
var amoutToMove : float;
function Update()
{
amoutToMove = speed * Time.deltaTime;
vad = Input.GetAxis("ShipSpeed") * Vector3.forward * amoutToMove;
}
Not sure about syntax I'm not a Java programmer
The problem isn't in the ship speed, however, thanks to your answer, I noticed the lack of the "Time.deltaTime". Thanks.
However my issue is still unsolved. The ship changes direction way to slow, and when it changes, it keeps going forward in the original direction unless the player keeps actioning the "ShipSpeed" Axis.
I'm not sure if it will work, but have you tried to calculate the agility the same way as I calculated amoutTo$$anonymous$$ove?
$$anonymous$$aybe you sould also translate the ship ins$$anonymous$$d of using the rigidbody.
It might help if you understood the numbers a little better. Check out the explanation here: http://www.youtube.com/watch?v=QbdpOau$$anonymous$$AQg
Your answer
Follow this Question
Related Questions
Rotation used as movement 4 Answers
rotation speed cap in 2D 0 Answers
Speed limit? 2 Answers
Speed of player depends on angle of rotation 1 Answer
Make object move in the direction is facing when rotated 1 Answer