head tracking

Posted By: silencer

head tracking - 04/14/09 20:05

So I want to have an NPC to look at the player when the player passes within a certain vector distance, but I want them to track the player with a "neck" rotation, kind of like they do in Hitman.

So far I have:
Code:
ent_animate(me,NULL,0,0);  // reset all bones
ent_animate(me,"idle",skill_1,ANM_CYCLE);
		
vec_set(temp,player.x); 
vec_sub(temp,silver_surfer.x);
vec_to_angle(silver_surfer.pan,temp); 
  		
temp1 = silver_surfer.pan + 90;

   	
   	if ((vec_dist(silver_surfer.x, player.x)) < 200) {
      	ent_bonerotate(me,"joint13",vector(temp1,0,0) ); // rotate neck bone
      }


I thought the above would work, but it seems to be rotating the entire entity. What gives?
Posted By: Pappenheimer

Re: head tracking - 04/15/09 19:53

This is the part where you rotate the entire entity:

vec_to_angle(silver_surfer.pan,temp);

You can directly do this:

vec_to_angle(temp1,temp);

or like this, if needed:

vec_to_angle(temp1, vector(temp.pan + 90, temp.tilt, temp.roll));
Posted By: silencer

Re: head tracking - 04/15/09 20:33

Hmm that still doesn't seem to update the "head" of the NPC. It just doesn't want to track the player position for some reason.
Posted By: Pappenheimer

Re: head tracking - 04/15/09 22:05

I have never used bones in this way.

What about separating the task in two:

Can you rotate the head with keys?
Something like this:
temp1.pan += key_r;
Posted By: silencer

Re: head tracking - 04/15/09 22:51

Yes it's something that should be possible (I've done it in other game engines) but for the life of me I can't figure out how to do this in A7.

Here's where I'm at right now:

Code:
while(1)
{
   	player_x = player.x;
	silver_x = silver_surfer.x;
	silver_pan = silver_surfer.pan;

	ent_animate(me,NULL,0,0);  // reset all bones
	ent_bonereset(me,"joint13");
	ent_animate(me,"idle",skill_1,ANM_CYCLE);

		
   	vec_set(temp,player_x); 
  	vec_sub(temp,silver_x);
  	vec_to_angle(silver_pan,temp); // now Silver Surfer looks at Player
 	temp1 = silver_pan;

   	
   	if ((vec_dist(silver_surfer.x, player.x)) < 200) {
   		ent_bonereset(me,"joint13");
      	ent_bonerotate(me,"joint13",vector(temp1,25,0) ); // rotate neck bone
      }


I'm not sure if I need to reset the bone in the "if" statement.

Also explain what you mean by splitting the task in two?

When the player walks near an NPC, the NPCs head should track the player based on a vector distance, not a key action, if that makes any sense.

I know I'm close, but the problem right now is that it seems the bone rotation is not being updated every frame, only once, and then that's it.
Posted By: Pappenheimer

Re: head tracking - 04/16/09 08:10

The splitting is meant for testing only.
I would implement a key action to test whether the bone rotation updates at all.

I don't understand why you use the variables instead of the vectors.

This part isn't necessary:

player_x = player.x;
silver_x = silver_surfer.x;
silver_pan = silver_surfer.pan;

But, if you want to use the variables, you should declare them this way:

var player_x[3];
var silver_x[3];
var silver_pan[3];

They have to be vectors, that means, they need an array of 3, if you use them with the vector instructions vec_set, vec_add etc..
Posted By: gri

Re: head tracking - 04/16/09 13:57

hi,

Dont use ent_bonerotate!

I did it and wasted much time.

problem #1
if you try any collsion-detection after the ent_bonerotate you will see that the bounding box doesnt moves to new position.
(maybe not tragic on head, but on moving legs,arms...)

problem #2
if the model moves with ent_animate and should turn the head with ent_bonerotate to you it will fail because on each "walkcycle" the headposition get reset.


Both problems I described here in the forums a few weeks/days ago.

If you want I can search the links.

I was realy happy as I saw the "ent_bone..." commands got realize in the engine and did easiely animated a model with it. I had full control at runtime via script to each little finger - it was very cool.
But without updated collision boundings it got useless for my needs and I throw it away.
JCL stated in "Future forum" it would slow down the engine if ent_bonerotate would update boundingbox too.



greetings,
gri
Posted By: Pappenheimer

Re: head tracking - 04/16/09 16:18

gri, thanks for the insights, but I don't understand the second point.
Can't you play the walkcycle and ent_bone_rotate the head right after that?

In case that isn't possible, one could add a bone animation to the model with the head rotating and set its animation depending the position of the target at which the head shall look, right?
Posted By: silencer

Re: head tracking - 04/16/09 18:15

On point#2, that's ridiculous that we can't manipulate a bone while using ent_animate. This is a very basic animation feature in most game engines.

Can one of the developers comment on this?
Posted By: ptrc1c

Re: head tracking - 04/16/09 20:17

Isn't this similar to workshop 23 in the online tutorial where part of the model tracks the movement of the mouse?.
Posted By: silencer

Re: head tracking - 04/17/09 16:44

It's similar but the big problem is that the result from a vec_to_angle doesn't update like it does for a "screen position" from the tutorial. At least I cannot get it to update which makes this problematic.
Posted By: silencer

Re: head tracking - 04/17/09 16:48

Oh fudge. I got it working literally 5 seconds ago.

When I clean up my code, I'll post the results so no one has to go through what I did trying to get this to work. smile
© 2024 lite-C Forums