Angle to Origin
Hi, is it possible to set an NPCs angle so he looks to a given origin?
|
Well, you have two origins:
1) the source_origin, ie. the current position of the NPC. If you don't have this, you can easily get it using entity_get_vector with EV_VEC_origin 2) the destination_origin, ie. where the NPC should be looking at You can compute the vector which needs to be added to source_origin in order to obtain destination_origin: Code:
dif_vector = source_origin - destination_origin;We can write a function called compute_look_vector, which computes the normalised look vector. It has three parameters: inSource, inDest, and outVec. Code:
But I assume you want the three angles, as HL uses them: pitch/yaw/roll. I wanted to write up how to compute them but it's too late so you can simply use the vector_to_angle (from the engine module) function for today. So here is our second version of the function, now with a different name, which computes the angles: Code:
I hope I haven't made a mistake. |
So umm.. Example of usage plz? kthx :)
|
Well, that's a tough one because I misunderstood the question.
However I think that's possible as well. We can use the function I posted to compute the angles. Then, we can set the NPC's yaw to the computed yaw value. We can safely ignore roll (because roll usually isn't associated with a looking-to computation and vec_to_angle should return 0 for it anyway). The problem is pitch - how can set the pitch of the head of the npc? I've looked at models from HL1 (barney, gman) and from cs 1.5 (hostage) and both only have controllers for setting the left-right rotation (yaw) of the head. So I'm afraid we can't set the pitch. Anyway, so we can set the rotation of the head. If you want to use this instead of setting the model's yaw angle directly, play around with the EV_BYTE_controller1 entvar. |
Hmm.. What about an example of making one player look towards the origin of another player? Maybe I misunderstood something.
|
Yup, I indeed think you misunderstood it. I think he wants a player model to look there - created by something like create_entity.
Anyway, your example: Code:
Or, uhh, that might work, I haven't tested it though. Also, I don't know whether v_angle is relative to the world coordinates or to the already set model angles. No idea XD test it. |
Well it doesn't work should the compute_look_angle return the OutAngle? And how?
|
| All times are GMT -4. The time now is 15:45. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.