x


Making objects turn smoothly

Hi guys, thanks for reading my question, I hope you could give me a hand with this...

The thing is, I'm kinda unsure of a way how to make my objects "turn smoothly" when they have to move towards a different direction that they are facing...

Basically, I created my own little waypoints system for a Rail-shooter game, where you move along a path. It works well and good, and events trigger well. But at this point in time, what I do to transition from heading to another waypoint is to turn towards the next waypoint point and move forward, which results in... Move to point, turn, move to next point. What I want to do is to change that into a starting moving towards point, turn slowly as it approaches the next point so that it will curve towards the next point, and continue heading straight for the next point... So that the turning will look more realistic of sorts.

Could anyone give me a hand with that?

more ▼

asked Oct 26 '10 at 04:01 PM

GamezAtWork gravatar image

GamezAtWork
233 26 29 35

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can interpolate a rotation by using Quaternion.Slerp. For example

public float turnspeed;
public Transform target;

void Update()
{
    Quaternion targetrotation=Quaternion.LookRotation(target.position-transform.position);
    transform.rotation=Quaternion.Slerp(transform.rotation,targetrotation,turnspeed*Time.deltaTime);
}

I'm sorry but I can't test this code because currently I'm not using my own PC.

more ▼

answered Oct 26 '10 at 07:36 PM

lhk gravatar image

lhk
520 14 15 24

Or you could use Quaternion.RotateTowards instead of the Slerp.

Dec 23 '10 at 12:24 PM Statement ♦♦
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x85
x77

asked: Oct 26 '10 at 04:01 PM

Seen: 1511 times

Last Updated: Oct 26 '10 at 04:01 PM