Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (henrybane), 1,499 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How to turn the my entity smoothly to a target? #332335
07/08/10 23:05
07/08/10 23:05
Joined: Nov 2003
Posts: 433
The Netherlands
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

Joined: Nov 2003
Posts: 433
The Netherlands
I know the vec_to_angle instruction and it's example and I tryed a lot with angles, ang() etc but I can't figure out how to actually turn it with a determined speed instead of just replacing a pan angle.

Can someone help? Thanks grin

Re: How to turn the my entity smoothly to a target? [Re: Toon] #332337
07/08/10 23:15
07/08/10 23:15
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline
Expert
Damocles_  Offline
Expert

Joined: Feb 2009
Posts: 2,154
the shortes function is


//this running constantly to adjust angles
while(1)
{
my_angle = target_angle * 0.9 + my_angle * 0.1; //0.9 + 0.1 =1 / sum must be 1
wait(1);
}

This is more of a princple, it is not accounting for the framereate
And it will make the "entity" rotate strangely
when the targetangle is more than 180 degrees off,

but its a good start

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 Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Very simple example:
Code:
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:
Code:
BotTurnTo(me,player.x);




Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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
B
bk9iq Offline
Member
bk9iq  Offline
Member
B

Joined: Jul 2010
Posts: 129
I tried this and it is working fine for me:


Quote:

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] #332363
07/09/10 08:43
07/09/10 08:43
Joined: Apr 2005
Posts: 274
austria
Ascalon Offline
Member
Ascalon  Offline
Member

Joined: Apr 2005
Posts: 274
austria
look in the manual
Code:
function approach_target_angle(angle)
{
  while (abs(my.pan - angle) > 0.1) {
    my.pan = angle;
	  smooth(my.pan,0.95);
    wait(1);
  }
}




my webside : www.ascalon.jimdo.de
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 Offline
Senior Member
Rasch  Offline
Senior Member

Joined: Jun 2008
Posts: 428
Originally Posted By: bk9iq
I tried this and it is working fine for me:


Quote:

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: Rasch] #332430
07/09/10 16:25
07/09/10 16:25
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
The one I gave, didn't work?!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

Joined: Nov 2003
Posts: 433
The Netherlands
Okay, I´m just going to ask it tongue 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 smile

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
P
Progger Offline
Senior Member
Progger  Offline
Senior Member
P

Joined: Sep 2009
Posts: 496
Here from aum 84 :
Code:
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 laugh


asking is the best Way to get help laugh laugh laugh
Re: How to turn the my entity smoothly to a target? [Re: Progger] #340995
09/09/10 13:34
09/09/10 13:34
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
The latest beta version has a script with such functions:

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

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1