# Rotation problem?

Hi all,

I have a strange problem with the rear swing arm of my motorcycle setup.

See the image above uses the following code to draw a red gizmo line from the swing arm pivot point to the centre of the rear wheel, and using the Vector3.Angle command I can get that angle.

``````Debug.DrawLine (wheelRL.transform.position, rear.transform.position, Color.red);

Debug.Log(Vector3.Angle(wheelRL.transform.position, rear.transform.position));
``````

However, when I try and set the angle of the swing arm, I get some strange effects? such as the swingarm rotating to all different angles etc?

I have tried the following:

``````bikerear.transform.localEulerAngles.x = Vector3.Angle(wheelRL.transform.position,rear.transform.position);
``````

and

``````bikerear.transform.localRotation = Quaternion.Euler(rear.transform.position, wheelRL.transform.position);
``````

But no different? anyone know what I am doing wrong?

Usually, finding the angle between two points (treated as vectors) isn’t of much use, and I’d guess maybe that’s not actually what you’re wanting to do here. Since I don’t know what you are trying to do I can’t really offer any specific suggestions, but generally speaking, it’s more common to compute angles between vectors than between points.

Hi Jesse, if you look at the image, you can see a red gizmo line that is drawn from the centre of the wheel to the pivot point of the swing arm.

This is being drawn dynamically by the following command.

``````Debug.DrawLine (wheelRL.transform.position, rear.transform.position, Color.red);
``````

So as the wheel moves based on the wheel collider being used and the suspension setting, the red gizmo line is redrawn using the angle returned, and it works.

However, when I use this returned angle to rotate the swing arm gameobject at its pivot point on the x axis, it works, but not all the time, as the bike moves, the swing arm jumps to different angles? its really strange.

Here is a quick video which should help, see that the red gizmo line is correctly angled all the time, but the swing arm goes a bit mad!

http://www.alabsoft.com/Unity3D/Bike%20Test/Bike%20Test.html

Fixed it myself!

Used LookAt

``````rear.transform.LookAt(wheelRL.transform.position);
``````

Simple in the end!