2 registered members (dr_panther, 7th_zorro),
1,203
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: get speed
[Re: Blobfist]
#472035
04/03/18 05:57
04/03/18 05:57
|
Joined: May 2005
Posts: 868 Chicago, IL
Dooley
User
|
User
Joined: May 2005
Posts: 868
Chicago, IL
|
If you are talking about c_move, it is a combination of the two vectors being used to move the entity. c_move(ENTITY* entity,VECTOR* reldist,VECTOR* absdist,var mode) So the .x portion of the first vector (reldist) added to the .x portion of the second vector (absdist) would give you the total forward speed of the entity. Then you would create three public variables, one for forward, one for side to side movement, and one for up/down movement. Just after your c_move event, you can assign those variables like this: c_move(my,my_move,nullvector,IGNORE_MODELS); my_forward = my_move.x; my_side = my_move.y; my_up = my_move.z; if you are using an absolute speed vector (like wind_speed or some other external factor) you could add this as well. c_move(my,my_move,wind_speed,IGNORE_MODELS); my_forward = my_move.x + wind_speed.x; my_side = my_move.y + wind_speed.y; my_up = my_move.z + wind_speed.z; Then use these three variables to access the speed of the object in question. There are probably other more efficient ways to do this, but this should work, and I don't think it will cause any kind of problem with memory.
Last edited by Dooley; 04/03/18 06:05.
|
|
|
Re: get speed
[Re: Dooley]
#472037
04/03/18 07:40
04/03/18 07:40
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
c_move returns distance covered, if it returns <=0 it means it's blocked by something in the direction you are trying to move. RTFM.
Last edited by Quad; 04/03/18 07:41.
3333333333
|
|
|
Re: get speed
[Re: Quad]
#472041
04/03/18 10:37
04/03/18 10:37
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hey It should be something like this:
action hero(){
var moving_distance = 0, moving_speed = 0, is_moving = 0;
while(my){
moving_distance = c_move(my, dist, absdist, FLAGS);
if(moving_distance > 0){
moving_speed = moving_distance / time_step;
is_moving = 1;
}
else{
moving_speed = 0;
is_moving = 0;
}
wait(1);
}
}
Greets!
|
|
|
Re: get speed
[Re: 3run]
#472221
04/16/18 21:38
04/16/18 21:38
|
Joined: Mar 2018
Posts: 37
Blobfist
OP
Newbie
|
OP
Newbie
Joined: Mar 2018
Posts: 37
|
Here I got the character stuck, thus it does not actually move. c_move however, thinks it is moving with an speed of 2.
my.move_speed = c_move(me,vector(dist_ahead,0,0),NULL,IGNORE_PASSABLE | GLIDE);
The question still remains, how can you get the actual speed on an entity?
Last edited by Blobfist; 04/16/18 21:40.
|
|
|
Re: get speed
[Re: Blobfist]
#472224
04/17/18 07:18
04/17/18 07:18
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
subtract the position before the move instruction from the position after the move instruction (giving you the vector the object has actually moved). this lets you calculate the length.
POTATO-MAN saves the day! - Random
|
|
|
Re: get speed
[Re: Dooley]
#472226
04/17/18 10:27
04/17/18 10:27
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
if you are using an absolute speed vector (like wind_speed or some other external factor) you could add this as well.
c_move(my,my_move,wind_speed,IGNORE_MODELS); my_forward = my_move.x + wind_speed.x; my_side = my_move.y + wind_speed.y; my_up = my_move.z + wind_speed.z; @Dooley I am sorry but your example is wrong. Those two vectors are in two different coordinate systems. It needs to convert one of them to the system of the other in order to get a rational result.
|
|
|
Re: get speed
[Re: Blobfist]
#472229
04/17/18 13:33
04/17/18 13:33
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Here I got the character stuck, thus it does not actually move. c_move however, thinks it is moving with an speed of 2.
my.move_speed = c_move(me,vector(dist_ahead,0,0),NULL,IGNORE_PASSABLE | GLIDE);
The question still remains, how can you get the actual speed on an entity? That's not a speed, but distance covered, and it will change with the framerate. Check my example, if you want to get framerate independent movement speed. Greets.
|
|
|
Re: get speed
[Re: 3run]
#472276
04/18/18 15:01
04/18/18 15:01
|
Joined: Mar 2018
Posts: 37
Blobfist
OP
Newbie
|
OP
Newbie
Joined: Mar 2018
Posts: 37
|
Sorry 3run, that didn't work. However, I found a solution that works very good : I set an fakeposition every second to the actual position of the character. If the character is suppose to move (established with c_move), but the actual position is the same or similar as the fake position, and if actual position stays as such for an second (or less), then the character is stuck!
var dist_ahead = 10;//speed to travel
var moving_distance = c_move(me,vector(dist_ahead,0,0),NULL,IGNORE_PASSABLE | GLIDE);//c_move code that establishes the moving distance
VECTOR fakepos;//this is the fake pos
var fakeposdist;//this will be the distance between the original position and the fake position
var poswait = 1;//Update the fake position every second
var calcstuck = 0;//we are not potentially stuck at the beginning
//////////
if(moving_distance>0)//character thinks it's moving
{
if(calcstuck >=1)//character is stuck!
{
my.move_speed = 0;//no movement
//preform I`m stuck action here
}
else{my.move_speed = moving_distance;}// movement is c_move speed
}
else{my.move_speed = 0;}//no movement
//
if(poswait>0){poswait -= time_step / 16;}//update fake position every second
else
{
poswait = 1;
vec_set(fakepos.x,my.x);
}
//
fakeposdist = vec_dist(my.x,fakepos.x);//find out distance between the fake position and actual position
if(fakeposdist <= 50){calcstuck += time_step / 16;}//if the distance if the same or very similar to the actual position, then check how long
else{calcstuck = 0;}//nothing is stuck
Last edited by Blobfist; 04/18/18 15:05.
|
|
|
Re: get speed
[Re: Blobfist]
#472277
04/18/18 15:02
04/18/18 15:02
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Sorry 3run, that didn't work. Sorry, but it works pretty good for me in all of my project. Anyway, glad that you figured things out.
|
|
|
|