I’m new to scripting and having trouble getting an object to slowly turn. Im basically just making my own version of the classic asteroid game and can’t get the ship to turn and move properly. If anyone can post the code here so I can see what I need to do that’d be great.
Also, please try to keep any explanations as simple as possible.
This function helps to to that:
Actually, I don’t think you need RotateTowards for this. You are working in 2D, right? So your rotation is described by a single number, degrees around the Z axis.
So you just need to add a bit of rotation to this on every frame. The key bit you’re probably missing is to multiply by Time.deltaTime, so that you add the appropriate amount for your current frame rate. (Of course this is just a guess since you didn’t show us your code.) It’d look something like this:
void Update() {
float ang = transform.eulerAngles.z;
ang += Input.GetAxis("Horizontal") * 360 * Time.deltaTime;
transform.rotation = Quaternion.Euler(0, 0, ang);
}
This will make your ship rotate up to 360 degrees (one full rotation) per second.
Please try that, and post back whatever you’re stuck on — including code (in code tags), so we can help.
1 Like