• Advertisement
Sign in to follow this  

How can I always turn a dog's head to a ball?

This topic is 4342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

We're developing a game just like a pet dog. We wanna throw a ball, and make the dog stare at the ball. The dog is make of skin mesh. So, how can I make the dog always stare at the ball? That means, how can I make the dog's head always turn to the ball? (I'm not a programmer from English-speaking country. So forgive me for my poor English.)

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
If you know how a skined mesh works the only thing you have to do is to compute a look at vector from dog's head to the object and rotate the head bone in that direction. If you don't understand what im talking about you should probably ask the person that wrote your skinned mesh code and he will explain to you how to rotate a bone.

Share this post


Link to post
Share on other sites
Depends, if you don't mind it look a bit rigid then it's a little bit of trigonometry, but if you have multiple joints you want to animate and have it look more fluid try googling for the term 'inverse kinematics'.

The rigid version:

Firstly, you'll need to define a unit vector that is the dog's 'looking forward' direction (let's call this vector D), most likely in the direction of the dog's nose. Next, find the vector from the dog's head to the ball. Do this using the position of the head (H) and the position of the ball (B), so the vector from head to ball will be V = (B-H).

You now have 2 directions, the direction from the dog's head to the ball and the direction that the dog's head is currently facing. What you want to do now is rotate the dogs head so that D (the direction the dog's head is facing) faces the same direction as V.

Rotating from 1 vector to another is common operation so won't go into detail about it, you should be able to find plenty of into on google about it. If you do need more help though feel free the ask.

Share this post


Link to post
Share on other sites
Thanks a lot!!

You just mentioned to use the IK(inverse kinematics). So how can I use IK in my D3D program? Thanks again.

Share this post


Link to post
Share on other sites
IK doesn't have anything to do with Direct3D, it's a mathematical technique used to calculate the angles of joints required to reach a goal, in this case the goal is to be looking at the ball. There's a couple of different methods around and the math can sometimes be a little daunting if you're only new to matrices but isn't too bad. Google will have plenty more info for you to work with than I'll be able to pick out of my brain.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement