Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Making a bone point to a target?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 Kaze   Members   

948
Like
0Likes
Like

Posted 13 April 2013 - 04:33 PM

This is in unity but uses vectors and quaternions that should work the same in most libraries.

 

http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.html

 

http://docs.unity3d.com/Documentation/ScriptReference/Vector3.html

 

I want to make a bone look at a target point but have two problems.

 

1: unity uses z+ forward and blender uses x-

 

2: the look at should avoid excessive twisting of the bone.

 

public class BoneLookAt : MonoBehaviour {
	

	
	// Use this for initialization
	void Start () {
		//save rest data
		restRot = this.transform.localRotation;
		
			//filter input
		Foward.Normalize();
		FowardQuaternionInverse = Quaternion.Inverse( Quaternion.LookRotation(Foward));
		
		
		
		
	}
	public Vector3 Foward = new Vector3(-1,0,0);
	private Quaternion FowardQuaternionInverse;
	
	private Quaternion restRot;
	
	public Vector3 GetTargetPosition(){
		return this.transform.position +  (this.transform.parent.rotation * restRot) * Foward;
	}
	public Quaternion LookAt(Vector3 v){
		//,transform.InverseTransformDirection(Vector3.up)
		 return  Quaternion.LookRotation(v-this.transform.position) * FowardQuaternionInverse;
		
	}
	
	private Vector3 ang = new Vector3();

	void Update () {
		Debug.DrawLine(this.transform.position,this.transform.position + this.transform.rotation * Foward);
		
		
		
		
		//
		this.transform.rotation = LookAt(GetTargetPosition());
		

		
		
		
		
	}
}


Edited by Kaze, 13 April 2013 - 04:33 PM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.