Gamestudio Links
Zorro Links
Newest Posts
Z strategies
by Fuchs
Yesterday at 17:27
saturation/contrast on different resolution?
by Kartoffel
Yesterday at 13:37
vec_for_vertex gap issue
by Dooley
04/19/18 22:15
FPS Damage effect
by 3run
04/19/18 20:51
website-related suggestions for the webmaster
by Fuchs
04/19/18 19:03
Algorithm for Detrend=SHUFFLE
by kujo
04/19/18 15:24
Separate entry and exit parameters optimization
by kujo
04/19/18 13:27
AUM Magazine
Latest Screens
Forgotten Tales - Demo version
RPG PARTY
Triton Wing now available on Steam
AckCon'17: Lotter vs The World
Who's Online
14 registered (3run, firecrest, AndrewAMD, jmlocatelli, PadMalcom, Don_Diego, kujo, Fuchs, mk_1, 2 invisible), 504 Guests and 4 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
stuvwx608784, Joderin, Fuchs, Don_Diego, jetomas59
17937 Registered Users
Topic Options
Rate This Topic
#472033 - 04/03/18 03:51 get speed
Blobfist Offline
Newbie

Registered: 03/20/18
Posts: 16
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.

Top
#472035 - 04/03/18 07:57 Re: get speed [Re: Blobfist]
Dooley Offline
User

Registered: 05/12/05
Posts: 568
Loc: 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.


Edited by Dooley (04/03/18 08:05)
_________________________
Check out "Star Explorers" on Steam:
http://store.steampowered.com/app/502720/Star_Explorers/

Anomalies released on Steam: http://store.steampowered.com/app/546780


Top
#472037 - 04/03/18 09:40 Re: get speed [Re: Dooley]
Quad Offline
Senior Expert

Registered: 10/27/07
Posts: 5142
Loc: İ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.


Edited by Quad (04/03/18 09:41)
_________________________
3333333333

Top
#472041 - 04/03/18 12:37 Re: get speed [Re: Quad]
3run Online
Senior Expert

Registered: 05/05/09
Posts: 5000
Loc: 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

Top
#472221 - 04/16/18 23:38 Re: get speed [Re: 3run]
Blobfist Offline
Newbie

Registered: 03/20/18
Posts: 16
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?


Edited by Blobfist (04/16/18 23:40)

Top
#472224 - 04/17/18 09:18 Re: get speed [Re: Blobfist]
Kartoffel Offline
Expert

Registered: 06/11/09
Posts: 2173
Loc: 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

Top
#472226 - 04/17/18 12:27 Re: get speed [Re: Dooley]
txesmi Offline
Serious User

Registered: 06/13/07
Posts: 1093
Loc: 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.

Top
#472229 - 04/17/18 15:33 Re: get speed [Re: Blobfist]
3run Online
Senior Expert

Registered: 05/05/09
Posts: 5000
Loc: 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

Top
#472276 - 04/18/18 17:01 Re: get speed [Re: 3run]
Blobfist Offline
Newbie

Registered: 03/20/18
Posts: 16
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



Edited by Blobfist (04/18/18 17:05)

Top
#472277 - 04/18/18 17:02 Re: get speed [Re: Blobfist]
3run Online
Senior Expert

Registered: 05/05/09
Posts: 5000
Loc: 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

Top


Moderator:  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | resources | magazine | manual | support faq | bugs

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) 3dgamestudio.net