1 registered members (henrybane),
1,499
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: How to turn the my entity smoothly to a target?
[Re: Damocles_]
#332339
07/08/10 23:17
07/08/10 23:17
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Very simple example:
VECTOR temp_vec2;
int BotTurnTo(ENTITY* ent, VECTOR* targ_vec)
{
vec_diff(temp_vec2.x,my.x,targ_vec.x);
vec_to_angle(targ_vec.x,temp_vec2.x);
ent.pan -= sign(ang(180 + ent.pan - targ_vec.x)) * 5 * time_step; // 5 speed
}
Example:
|
|
|
Re: How to turn the my entity smoothly to a target?
[Re: 3run]
#332362
07/09/10 08:34
07/09/10 08:34
|
Joined: Jul 2010
Posts: 129
bk9iq
Member
|
Member
Joined: Jul 2010
Posts: 129
|
I tried this and it is working fine for me: VECTOR temp_for_turning; action arrow() { while(1) { vec_set(temp_for_turning, player.x); vec_sub(temp_for_turning, my.x); vec_to_angle(my.pan,temp_for_turning); wait(1); } }
just attach this action to the entity u want to be rotated towards the player..
|
|
|
Re: How to turn the my entity smoothly to a target?
[Re: bk9iq]
#332364
07/09/10 08:46
07/09/10 08:46
|
Joined: Jun 2008
Posts: 428
Rasch
Senior Member
|
Senior Member
Joined: Jun 2008
Posts: 428
|
I tried this and it is working fine for me: VECTOR temp_for_turning; action arrow() { while(1) { vec_set(temp_for_turning, player.x); vec_sub(temp_for_turning, my.x); vec_to_angle(my.pan,temp_for_turning); wait(1); } }
just attach this action to the entity u want to be rotated towards the player.. He wants to turn it smoothly.
|
|
|
Re: How to turn the my entity smoothly to a target?
[Re: Toon]
#340817
09/07/10 19:40
09/07/10 19:40
|
Joined: Nov 2003
Posts: 433 The Netherlands
Toon
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2003
Posts: 433
The Netherlands
|
Okay, I´m just going to ask it Is there a simple example of an entity moving on a closed path with smooth turning. I could only find an example in the manual with path_spline. It doesnt have to scan for paths or anything, just an asigned path is fine... I hope someone can help, thanks
|
|
|
Re: How to turn the my entity smoothly to a target?
[Re: Toon]
#340822
09/07/10 20:24
09/07/10 20:24
|
Joined: Sep 2009
Posts: 496
Progger
Senior Member
|
Senior Member
Joined: Sep 2009
Posts: 496
|
Here from aum 84 :
Q: I have a car model; how do I make it follow the direction of the path smoothly?
A: Here's a simplified version of the code used in my car demo.
#define car_speed skill55
SOUND* aiskids1_wav = "aiskids1.wav";
SOUND* carai1_wav = "carai1.wav";
ENTITY* dummy1;
ENTITY* carai1_dummy;
ENTITY* carai1;
action car_ai()
{
carai1 = my;
var distance = 0;
var previous_pan;
var following_pan;
var min_speed = 20;
var max_speed;
var carai_engine;
var engine_factor;
var dist_z;
var skids_once = 0;
VECTOR last_pos[3];
VECTOR direction[3];
VECTOR temp[3];
max_speed = 35;
dummy1 = ent_create(NULL, nullvector, NULL);
// create another (carai1_dummy) dummy entity that will move on the path
// the ai car will use the same x, y, pan, tilt and roll with the carai1_dummy entity that moves on the path
// but will compute its own z using c_trace; this way, the nodes don't have to be place precisely above the ground
carai1_dummy = ent_create(NULL, nullvector, NULL);
path_set(dummy1, "path_001"); // make sure to name your path this way
engine_factor = 2 + random(2); // start with a random engine sound frecquency each and every time
carai_engine = ent_playloop(carai1, carai1_wav, 300); // start playing the car ai engine sound in a loop
while(1)
{
previous_pan = carai1.pan;
// place the carai1 entity on the path
path_spline(dummy1, carai1_dummy.x, distance);
distance += dummy1.car_speed * time_step;
// let carai1 look ahead
vec_diff(direction, carai1_dummy.x, last_pos);
vec_to_angle(carai1_dummy.pan, direction);
vec_set(last_pos, carai1_dummy.x);
carai1.pan = carai1_dummy.pan;
carai1.tilt = carai1_dummy.tilt;
carai1.roll = carai1_dummy.roll;
carai1.x = carai1_dummy.x;
carai1.y = carai1_dummy.y;
vec_set (temp.x, carai1_dummy.x);
temp.z -= 2000;
dist_z = c_trace(carai1_dummy.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | IGNORE_MODELS); // ignore the "real" carai
carai1.z = carai1_dummy.z - dist_z + 35; // 35 = experimental value
// sets a variable car ai engine frequency, depending on the speed of the car
snd_tune(carai_engine, 0, dummy1.car_speed * engine_factor, 0);
wait(1);
following_pan = carai1.pan;
if (abs(following_pan - previous_pan) > 1) // sudden direction change? Then lower the speed of the AI car
{
dummy1.car_speed -= 4 * time_step;
if (skids_once == 0)
{
skids_once = 1;
if (random(1) > 0.9)
{
ent_playsound(dummy1, aiskids1_wav, 3000);
}
}
}
else
{
skids_once = 0;
dummy1.car_speed += 2 * time_step;
}
dummy1.car_speed = clamp(dummy1.car_speed, min_speed, max_speed);
}
}
WFG Progger
|
|
|
|