Enemy bend at waist

Posted By: Ruben

Enemy bend at waist - 10/24/15 11:26

I am trying to make it so that an enemy will bend at the waist as needed, to always have its upper body facing the player.

So for example, if the player is walking up stairs, and the enemy attacks the player from up the stairs, the enemy should bend forward at the waist so that its upper body is facing down directly toward the player.

I am assuming that ent_bonerotate() would be used for this? I am trying to make this happen, but so far it is not working. This is the code I have so far:

Code:
action monster_code()
{
   ...

   ent_bonereset(my,"waist");

   ...

   while(1)
   {
      ...

      limit=clamp(camera.tilt,-53,53); //min max
      ent_bonerotate(my, "waist", vector(0,limit,0));

      wait(1);
   }
}



I am assuming that I have to somehow manipulate the ent_bonerotate() function to make it so the enemy is bending at the waist, where its upper body is continually facing the player at all times while attacking.

Does anyone have a clue on how I could start on doing this?
Posted By: txesmi

Re: Enemy bend at waist - 10/24/15 13:44

Hi,
reading 23rd workshop would take you some doubts off.

Originally Posted By: Online Tutorial - Workshop 23: Bones
Why do we need to reset the bone first? Let's assume that bone_angle.pan is set to 30 degrees at a certain moment. Then, let's imagine that the player moves the mouse a little further in the following frame, until bone_angle.pan reaches 35 degrees. But the gun was already rotated by 30 degrees in the previous frame, so it would now rotate another 35 degrees, setting the pan angle to 30 + 35 = 65 degrees!

This is what would happen if we wouldn't use that "ent_bonereset" instruction inside the while loop. By using ent_bonereset we discard the old angles every frame, so the bone will only get the newly computed angles (pan = 35 degrees in my previous example)


Salud!
Posted By: Anonymous

Re: Enemy bend at waist - 10/24/15 16:44

http://www.conitec.net/beta/avec_to_angle.htm

vec_to_angle (ANGLE* ang, VECTOR* dir);
Computes the pan and tilt angles of a direction vector, and places them into the pan and tilt parameters of an Euler angle. Very useful for trading an angle for a direction, thus computing the angles to a target.

Code:
function turn_towards_target()
{
  // get the direction from the entity MY to the entity YOU
  vec_set(temp,your.x); 
  vec_sub(temp,my.x);
  vec_to_angle(my.pan,temp); // now MY looks at YOU
}



Code:
action monster_code()
{
   ...
   VECTOR vec_temp;
   VECTOR vec_bend;
   var limit2=0;
   var limit3=0;  

   ...

   while(1)
   {
      ...
       // get the direction from the entity MY to the entity YOU
  vec_set(vec_temp,player.x); 
  vec_sub(vec_temp,my.x);
  if(abs(vec_bend.pan) >90)
  vec_to_angle(vector(my.pan,0,0),vec_temp); // now MY
else
{
vec_to_angle(vec_bend,vec_temp); // now MY looks at YOU
       ent_bonereset(my,"waist");
      limit=clamp(vec_bend.tilt,-53,53); //min max
      limit2=clamp(vec_bend.pan,-90,90); //min max
      limit3=clamp(vec_bend.roll,-25,25); //min max
      ent_bonerotate(my, "waist", vector(limit2,limit,limit3));
}
      wait(1);
   }
}



When do we start getting paid for this?

Lol , have fun
Mal

EDITED- Code correction
Posted By: Ruben

Re: Enemy bend at waist - 10/25/15 05:21

Originally Posted By: Malice
http://www.conitec.net/beta/avec_to_angle.htm

vec_to_angle (ANGLE* ang, VECTOR* dir);
Computes the pan and tilt angles of a direction vector, and places them into the pan and tilt parameters of an Euler angle. Very useful for trading an angle for a direction, thus computing the angles to a target.

Code:
function turn_towards_target()
{
  // get the direction from the entity MY to the entity YOU
  vec_set(temp,your.x); 
  vec_sub(temp,my.x);
  vec_to_angle(my.pan,temp); // now MY looks at YOU
}



Code:
action monster_code()
{
   ...
   VECTOR vec_temp;
   VECTOR vec_bend;
   var limit2=0;
   var limit3=0;  

   ...

   while(1)
   {
      ...
       // get the direction from the entity MY to the entity YOU
  vec_set(vec_temp,player.x); 
  vec_sub(vec_temp,my.x);
  if(abs(vec_bend.pan) >90)
  vec_to_angle(vector(my.pan,0,0),vec_temp); // now MY
else
{
vec_to_angle(vec_bend,vec_temp); // now MY looks at YOU
       ent_bonereset(my,"waist");
      limit=clamp(vec_bend.tilt,-53,53); //min max
      limit2=clamp(vec_bend.pan,-90,90); //min max
      limit3=clamp(vec_bend.roll,-25,25); //min max
      ent_bonerotate(my, "waist", vector(limit2,limit,limit3));
}
      wait(1);
   }
}



When do we start getting paid for this?

Lol , have fun
Mal

EDITED- Code correction


Error in ''monsterCode.c'
'pan': is not a member of 'VECTOR'
< if(abs(vec_bend.pan) >90)
>
Posted By: Ruben

Re: Enemy bend at waist - 10/25/15 05:56

Originally Posted By: txesmi
Hi,
reading 23rd workshop would take you some doubts off.

Originally Posted By: Online Tutorial - Workshop 23: Bones
Why do we need to reset the bone first? Let's assume that bone_angle.pan is set to 30 degrees at a certain moment. Then, let's imagine that the player moves the mouse a little further in the following frame, until bone_angle.pan reaches 35 degrees. But the gun was already rotated by 30 degrees in the previous frame, so it would now rotate another 35 degrees, setting the pan angle to 30 + 35 = 65 degrees!

This is what would happen if we wouldn't use that "ent_bonereset" instruction inside the while loop. By using ent_bonereset we discard the old angles every frame, so the bone will only get the newly computed angles (pan = 35 degrees in my previous example)


Salud!


I tried incorporating this code:

Code:
action monster_code()
{
   ...

   ent_bonereset(my,"waist");

   ...

   while(1)
   {
      ...

      ent_bonerotate(my, "waist", vector(0, player, 0));

      wait(1);
   }
}



The monster charges toward me using the above code. It seems to be bending the monster's waist. However, the monster's waist is bent all the way back when charging the player, when the monster should bend a little forward to face its upper body toward the player and strike the player, since the monster is taller than the player.

I tried changing this line in the above code:

Code:
ent_bonerotate(my, "waist", vector(0, player, 0));



to:

Code:
ent_bonerotate(my, "waist", vector(0, player.tilt, 0));



or

Code:
ent_bonerotate(my, "waist", vector(0, player.y, 0));



When I do either of these two options, the monster_code() action crashes when I run the game. It does not crash when I use the original code.
Posted By: Anonymous

Re: Enemy bend at waist - 10/25/15 18:29

Code:
Error in ''monsterCode.c'
'pan': is not a member of 'VECTOR'
< if(abs(vec_bend.pan) >90)
>


You should know how to fix this.!
Change vec_bend.pan to vec_bend.x
pan is a member of ANGLE
x is a member of VECTOR
Posted By: Anonymous

Re: Enemy bend at waist - 10/25/15 18:37

Quote:
Originally Posted By: txesmi
Hi,
reading 23rd workshop would take you some doubts off.

Originally Posted By: Online Tutorial - Workshop 23: Bones
Why do we need to reset the bone first? Let's assume that bone_angle.pan is set to 30 degrees at a certain moment. Then, let's imagine that the player moves the mouse a little further in the following frame, until bone_angle.pan reaches 35 degrees. But the gun was already rotated by 30 degrees in the previous frame, so it would now rotate another 35 degrees, setting the pan angle to 30 + 35 = 65 degrees!

This is what would happen if we wouldn't use that "ent_bonereset" instruction inside the while loop. By using ent_bonereset we discard the old angles every frame, so the bone will only get the newly computed angles (pan = 35 degrees in my previous example)


Salud!


I tried incorporating this code:

Code:
action monster_code()
{
...

ent_bonereset(my,"waist");

...

while(1)
{
...

ent_bonerotate(my, "waist", vector(0, player, 0));

wait(1);
}
}



The monster charges toward me using the above code. It seems to be bending the monster's waist. However, the monster's waist is bent all the way back when charging the player, when the monster should bend a little forward to face its upper body toward the player and strike the player, since the monster is taller than the player.

I tried changing this line in the above code:

Code:
ent_bonerotate(my, "waist", vector(0, player, 0));



to:

Code:
ent_bonerotate(my, "waist", vector(0, player.tilt, 0));



or

Code:
ent_bonerotate(my, "waist", vector(0, player.y, 0));



When I do either of these two options, the monster_code() action crashes when I run the game. It does not crash when I use the original code.



First like i did in my code and txesmi is telling add ent_bonerest inside the while() loop.

Next you first try you passed a pointer into the tilt value of the ent_bonerotate( .....vector(0,player,0)...) God knows what the value of the pointer was

Next in the second - This one should not crash - ent_bonerotate(my,"waist", vector(0, player.tilt, 0));
However it shouldn't work the way you want.

It may be that if the last to are failing the the pointer "player" is not assigned. Crashing makes no sense - these just should not work the way you want.
Posted By: Anonymous

Re: Enemy bend at waist - 10/25/15 18:40

ANGLE VECTOR
pan == x
tilt == y
roll == z


"Mans reach exceeds his grasp"

Sorry to tell you, but you should take a week or two to study, if you do not know what is and how to use pointers, ANGLE and VECTOR.

I learned by seeing post then trying to figure out how to fix the issues. You're not asking for a little help, your're asking people to write code for things you haven't even learned.

Posted By: Ruben

Re: Enemy bend at waist - 10/25/15 22:08

Originally Posted By: Malice
ANGLE VECTOR
pan == x
tilt == y
roll == z


"Mans reach exceeds his grasp"

Sorry to tell you, but you should take a week or two to study, if you do not know what is and how to use pointers, ANGLE and VECTOR.

I learned by seeing post then trying to figure out how to fix the issues. You're not asking for a little help, your're asking people to write code for things you haven't even learned.


I thank you for your help, but just for your information, I have never asked anyone to write code for me. You chose to do that on your own.

Bones is also a new topic for me, and I am seeking to understand it better.

Thank you for the advice on angle versus vector. It helped me understand it better.
Posted By: Anonymous

Re: Enemy bend at waist - 10/25/15 22:46

It's not your lack of bone knowledge, it's your lack of understanding vector, angle and pointers.

As for writing code, well it's just easier then 3-4 days of posting back in fourth.

I could have said

// find the player in ang space
vec_to_angle(.....);
//check if player is more then 90* +- me
if(abs(vec_bend.x>90)
... turn my pan to face player
// Else - bend my body to face player
ent_bonerest(...)
...fill limit1, limit2 limit3 from vec_bend.xyz
ent_bonerotate(.....vector(limit1,limit2,limit3)...);


However then I would have days of questions. It's just a observation.
Good luck have fun.
Mal
Posted By: Anonymous

Re: Enemy bend at waist - 10/26/15 04:46

Code:
action monster_code()
{
	
	VECTOR vec_temp;
	ANGLE vec_bend;
	ANGLE ang_bpdiff;
	var limit=0;
	var limit2=0;
	var limit3=0;  

	while(1)
	{
		// get the direction from the entity MY to the entity YOU
	vec_to_angle(vec_bend.pan,vec_diff(NULL,player.x,my.x));
		//    now MY looks at YOU
		ang_diff(ang_bpdiff,vec_bend.pan,my.pan);
		if(abs(ang_bpdiff.pan) >90)
		{
			ent_bonereset(my,"bip01 Spine1");
			vec_to_angle(my.pan,vec_diff(NULL,player.x,my.x));
			ent_bonereset(my,"bip01 Spine1"); // may be overkill
			my.tilt=0;
			my.roll=0;
		} 
		else
		{
			ent_bonereset(my,"bip01 Spine1");
			limit=clamp(ang_bpdiff.tilt,-53,53); //min max
			limit2=clamp(ang_bpdiff.pan,-90,90); //min max
			limit3=clamp(ang_bpdiff.roll,-25,25); //min max
			ent_bonerotate(my, "bip01 Spine1", vector(limit2,limit,limit3));
		}
		wait(1);
	}
}



Code 100% tested and working with Tusker.mdl

I got bored and felt like doing this. Think it's cool. BTW in the bottom left of MED - select the bone - you'll see two name blocks - the bone name bip01 Spine1 and the word"bone". the name is not bone.

No need for a "thank you"- I thought playing with vec_to_ang and Ang_diff would be a fun reminder. Now I played with bones makes me want to build a bone animation system. Lol to much work...

Have fun ,game dev on bill and ted
Mal
Posted By: Ruben

Re: Enemy bend at waist - 10/26/15 08:04

I ended up trying to edit and sync your original code with my code. I believe it is working. Thank you.

I tried using your new code, but the monster_code is crashing.
Posted By: Anonymous

Re: Enemy bend at waist - 10/26/15 16:31

Yeah ok, have fun. The code is run 100% crash free in my project so I can't fix that.


Have fun..
Mal

Code:
action monster_code()
{
	
	VECTOR vec_temp;
	ANGLE vec_bend;
	ANGLE ang_bpdiff;
	var limit=0;
	var limit2=0;
	var limit3=0;  

	while(1)
	{
		
		// get the direction from the entity MY to the entity YOU
		set(my,LIGHT);
		vec_to_angle(vec_bend.pan,vec_diff(NULL,player.x,my.x));
		//    now MY looks at YOU
		vec_sub(vec_bend.pan,my.pan);
		if(abs(vec_bend.pan) >90)
		{
			my.red=255;
			ent_bonereset(my,"bip01 Spine1");
			vec_to_angle(my.pan,vec_diff(NULL,player.x,my.x));
			ent_bonereset(my,"bip01 Spine1");
			my.tilt=0;
			my.roll=0;
		} 
		else
		{
			my.red=0;
			ent_bonereset(my,"bip01 Spine1");
			limit=clamp(-vec_bend.tilt,-25,25); //min max
			limit2=clamp(vec_bend.pan,-90,90); //min max
			limit3=clamp(vec_bend.roll,-25,25); //min max
			ent_bonerotate(my, "bip01 Spine1", vector(limit2,limit,0));
		}
		wait(1);
	}
}

© 2024 lite-C Forums