- Home /
Question by
dragonking300 · Jan 29, 2017 at 05:27 AM ·
c#scripting problembeginnerquaternions
How to use quaternions to change the rotation of a object when you have a joint linking 2 objects?
I am trying to make a swinging axe that swings left to right but the problem is and I think I know how to change the rotation of an object with quaternions but the problem is I am using a hinge joint right now to connect the swinging axe part to another floating immobile object with a invisible gamejobject as the hinge joint and when I activate my script
How my script is supposed to work
Initialize the rotation of the axe (working) Have my script change the quaternions so that it rotates around the joint hinge....(Not working at all)
My script
using UnityEngine; using System.Collections;
public class physics : MonoBehaviour {
public Transform StartingPosition;
public Quaternion Starter;
public Quaternion Target;
public float speed = 0.1f;
void Start()
{
StartingPosition.transform.rotation = Quaternion.Euler(0, 0, 0);
Starter = new Quaternion(0, 0, 100, 0);
Target = new Quaternion(0, 0, -100, 0);
}
// Update is called once per frame
void Update ()
{
StartingPosition.transform.rotation = Quaternion.Slerp(Starter, Target, Time.time * speed);
}
}
Edit: Oops, I forgot to mention my StartingPosition transform is attached to my axe part! .
untitled.png
(13.7 kB)
Comment