# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### AppGameKit Classic Chat / [SOLVED] Object Bone look at rotation help

Message
Posted: 12th May 2023 04:22 Edited at: 12th May 2023 04:24
So I need when my player comes up to other objects for there heads to point to them.

I have this and it works but there heads turn all the way around. So I need to figure out a way to limit there head bone rotation to 90 deg.

Here is the code I am fighting with and I used a lot of different ways and nothing works.

Right now i figured to have the bone look at the player with getting the bone ang z but well, that is pointless.

The author of this post has marked a post as an answer.

Posted: 12th May 2023 14:14 Edited at: 12th May 2023 14:18
I'd recommend using the angle between your player object as a whole and the item to determine if the head should be pointed at it or not. This can be done using the dot product of two heading vectors on the XZ plane, one for the player's forward direction and one for a dummy object that is set to always look at the item.

Posted: 12th May 2023 15:53 Edited at: 12th May 2023 16:00
And here's a method that doesn't use a dummy object, as I know some people don't like using them. Not sure which method would be more performant, though.

Posted: 12th May 2023 21:48
hendron thank you, I will check it out today and let you know. This is such a big help.
Posted: 13th May 2023 03:20
Ok this kind of works but only when I am looking at the other object, If I am behind him and still looking at him his head still turn's all the way around as it is not set to pos but angles.
Posted: 13th May 2023 13:06
Not sure I follow. Can you post a video of what's happening? The example I posted is meant to show how you can determine if an object is within 90 degrees of the player avatar's forward direction (as a whole, not the head bone). The logic being that you would only set the head bone to look at the object if it falls into this range. If it falls outside, set the head bone back to its normal orientation.
Posted: 13th May 2023 13:41
Ok picture one shows a normal head rotation when I am in front of him.

picture 2 shows head turned into body when I'm behind him or even beside him.

No matter how far away I am I still get a in range=1 when I am turned to him.

code I'm using and thanks for looking.

Posted: 13th May 2023 14:00 Edited at: 13th May 2023 14:05
This post has been marked by the post author as the answer.
Ah, so you're talking about the NPC looking at the Player? In that case, you need to run the code from the perspective of the NPC. I've turned the code into a function that should be able to be used on any character.

you can call it like this:

Let me know if it works. I haven't tested it myself because I'd need to setup a character for it to do so.

 updated some of the variable names to make more sense in the context of the function
Posted: 13th May 2023 14:12
GameControls.agc:614: error: Cannot convert type "Integer" to "Type"

It is trying to convert my player integer into a type and does not like this.

lookTarget as tVector3
lookTarget.x = bonex#
lookTarget.y = boney#
lookTarget.z = bonez#
Posted: 13th May 2023 14:15
use lookTarget instead of Player (I'm assuming from your previous code snippet that bonex#, boney# and bonez# are the target coordinates you want the NPC to look at?)
Posted: 13th May 2023 14:18
Oh lol, my mistake, it works, it works good, But his head snaps back to to the rest head pos real fast like he was hit by something lol.

It looks funny. But it works.

One problem at a time I always say.
Posted: 13th May 2023 14:23
Cool, glad it worked. Look into object tweens to fix the head snapping.
Posted: 13th May 2023 14:24
Ok sure thing.

Thank you very much for the help
Posted: 13th May 2023 14:25 Edited at: 13th May 2023 14:26
double post i guess