Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Nymphodora, AndrewAMD, TipmyPip, Quad, Imhotep), 847 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
get speed #472033
04/03/18 01:51
04/03/18 01:51
Joined: Mar 2018
Posts: 37
Blobfist Offline OP
Newbie
Blobfist  Offline OP
Newbie

Joined: Mar 2018
Posts: 37
Hello everybody,

I was wondering how I could get the actual speed on an entity (moving using c_move).

The actual speed is needed in order to determin, if the entity is moving of not, aka. is potentially stuck or not.

I could only find commands to get the speed of PhysX objects in the Manuel, which unfortunately did not explain the build up.

Speed = distance/time, so is it possible to get the value of the x and y axis of the entity every frame, without killing the memory?

Please help me out.

Re: get speed [Re: Blobfist] #472035
04/03/18 05:57
04/03/18 05:57
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline
User
Dooley  Offline
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.
Quote:
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 Online
Senior Expert
Quad  Online
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 Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Hey

It should be something like this:
Code:
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!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: get speed [Re: 3run] #472221
04/16/18 21:38
04/16/18 21:38
Joined: Mar 2018
Posts: 37
Blobfist Offline OP
Newbie
Blobfist  Offline 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.

Code:
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 Offline
Expert
Kartoffel  Offline
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 Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Originally Posted By: Dooley
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 Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: Blobfist
Here I got the character stuck, thus it does not actually move.
c_move however, thinks it is moving with an speed of 2.

Code:
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.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: get speed [Re: 3run] #472276
04/18/18 15:01
04/18/18 15:01
Joined: Mar 2018
Posts: 37
Blobfist Offline OP
Newbie
Blobfist  Offline OP
Newbie

Joined: Mar 2018
Posts: 37
Sorry 3run, that didn't work.


However, I found a solution that works very good grin :

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!

Code:
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



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

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: Blobfist
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.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

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