How to aim in 3rd person shooter

Posted By: MAGA

How to aim in 3rd person shooter - 01/14/09 06:16

In my project there are few non-moving camera, they allways looks at player, I need to make a code to aim, like in Resident Evil if i press key_* then player model mast play animation "aim", turn to closer enemy and around the enemy mast apear curcle. How can I do that? Please give me an example.
Posted By: the_clown

Re: How to aim in 3rd person shooter - 01/14/09 08:40

I'm at school at the moment so I can't give you exact code, but I did something like that before;
First, for the turning, you'll have to check if there's an enemy nearby; I'd use c_scan for that, it returns the you-pointer you need. Then you'll have to turn the player, what should be easy; take a look at vec_to_angle in the manual. Last thing to do are the animation and the circle.
If you don't want the player to be able to walk while aiming, you simply can blend into the "aim" animation (ent_blend).
The circle should be a panel, take a look at vec_for_screen in the manual.
I'll try to give you an example right when I'm back home.
Posted By: MAGA

Re: How to aim in 3rd person shooter - 01/14/09 09:07

Thank you dude smile I'll try, and I waiting for example smile
Posted By: MAGA

Re: How to aim in 3rd person shooter - 01/14/09 16:39

Still waiting smile
Posted By: the_clown

Re: How to aim in 3rd person shooter - 01/23/09 13:25

Excuse me for this, I just have forgotten this....
I am so ashamed.
However, let's see.
You want the model to play the "aim" animation, turn to the next enemy and you want the enemy to be selected by a circle, right.

I don't know how your code looks like, but I suppose you have a loop running in the player action.
Now, in this loop, you have to check if the player is pressing a certain key. Then you have to check for the enemies, turn the player to the nearest one and play the animation:

first, define a entity:

ENTITY* selected_enemy;

////////////////////////////////////////////////////////////////////
if(mouse_right)
{
c_scan(my.x,my.pan,vector(360,360,3000),IGNORE_PASSABLE);
if(you)
{
if(you.skill6 == 1) // the enemy should have set skill6 to 1
{
selected_enemy = you;
vec_set(temp,your.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp); // now MY looks at YOU
my.tilt = 0;
vec_set(my.move_x,vector(0,0,0));
//replace move_x with the skill you are using for moving

my.skill3 += 20*time_step; // blend factor for 1-frame animation
my.skill3 = min(my.skill3,100); // clip at 100 percent
}
}
}
else
{
my.skill3 -= 20*time_step;
my.skill3 = max(my.skill3,0); // clip at 0 percent
}

ent_blend("aim",0,my.skill3);
/////////////////////////////////////////////////////////////////////////////

you should put this whole code snippet (exept for the entity definition) at the end of your player loop (but before the wait(1) of course).

for the circle just define a panel with the circle bitmap and write a function that permanently sets the world coordinates of the selected_enemy entity to 2d coordinates. (vec_to_screen).
I'm sorry if this doesn't work right, just post then. I've put this together in ten minutes using the online manual and my memories; I don't have access to my own code now.
© 2024 lite-C Forums