Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/08/26 22:41
Stooq now requires an API key
by VHX. 06/08/26 20:14
ZorroGPT
by TipmyPip. 06/06/26 12:36
Zorro 3.01 recoded MMI function issue
by TipmyPip. 06/04/26 05:44
SGT_FW
by Aku_Aku. 05/31/26 11:05
Issues resuming trades on Demo account
by Martin_HH. 05/22/26 13:31
XTB
by pr0logic. 05/18/26 12:27
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (TipmyPip), 3,586 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Seraphinang, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
moving an entity along the hypotenuse of an equation. #340244
09/02/10 12:07
09/02/10 12:07
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
I have a code that moves an entity along a pre defined path. It works fine but could be better. Essentially, I need the entity to move along a path that is calculated from the entity's starting x and y positions to its ending x,y positions. The entity should gradually increase/decrease its x/y movement based on this result. I tried to use some basic algebra to get this result but , it wont work. I would like for the formula/code to calculate the length of the hypotenuse using a percentage scale so I only need to adjust a speed skill/variable during runtime. Any ideas???

Re: moving an entity along the hypotenuse of an equation. [Re: exile] #340610
09/06/10 04:48
09/06/10 04:48
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Okaaaayyyy, maybe it would be a bit better if I drew a picture...



As you can see, I have two positions which will be stored in vectors. During runtime, I need the entity to move smoothly to the defined vector position. In this case, I use a right triangle as the example. The hypotenuse is colored red to show the line I would like the entity to move on. I assume the same effect could be created using a point&click style movement so I'll do some research.

Re: moving an entity along the hypotenuse of an equation. [Re: exile] #340638
09/06/10 09:49
09/06/10 09:49
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
why not use vec_diff?


3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: moving an entity along the hypotenuse of an equation. [Re: painkiller] #340647
09/06/10 10:25
09/06/10 10:25
Joined: Jun 2006
Posts: 379
Flevoland, 5 meters under wate...
Roel Offline
Senior Member
Roel  Offline
Senior Member

Joined: Jun 2006
Posts: 379
Flevoland, 5 meters under wate...
as painkiller said, you can use vec diff, to calculate the direction of the movement
then you normalize that direction to the speed you want the entity to move.
the following frames, you add the resulting vector to the position of your entity

like this:

vec_diff(vec_result,vec_start,vec_end);
vec_normalize(vec_result,speed);
while(vec_dist(my,x,vec_end) > speed)
{
vec_add(my.s,resultvec);
wait(1);
}

it isn't tested, and also it doesn't work with the time_step variable.
I hope this helps!


Check out the throwing game here: The throwing game
Re: moving an entity along the hypotenuse of an equation. [Re: Roel] #340703
09/06/10 22:39
09/06/10 22:39
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
You see, this is why the manual needs a better search engine. I never even knew about that function tongue Thanks for the help guys, I'll look into how this is used and attempt to properly place this function in my code (not Roel's example, just the vec_diff command in general).


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

Gamestudio download | 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