Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Moving the player along an angle. (https://forums.graalonline.com/forums/showthread.php?t=134259898)

Jiroxys7 07-20-2010 07:24 PM

Moving the player along an angle.
 
I'm trying to move the player along an angle from point A to point B using getangle(). However I'm not quite sure how to pull out a set of coordinates that are along that angle. Though I dont suppose there would be any way to somehow use move() on the actual player as an alternative is there?

Any advice?

Loriel 07-20-2010 08:02 PM

Quote:

Originally Posted by Jiroxys7 (Post 1588702)
I'm trying to move the player along an angle from point A to point B using getangle(). However I'm not quite sure how to pull out a set of coordinates that are along that angle. Though I dont suppose there would be any way to somehow use move() on the actual player as an alternative is there?

Any advice?

If you know how far you would want to move the guy if it was in a straight horizontal line, say, r tiles, you can get how far to move him for the angle a on both the x and y axis by doing something like dx = r * sin(a); dy = r * cos(a);, you might have to **** with the signs or swap sin and cos depending on where you define a=0 to be, I forgot what getangle() does there.

Loriel 07-20-2010 08:08 PM

Basically look up trigonometry on wikipedia, I am sure they have useful diagrams, I was going to post one but it appears I lost it. Also probably more like -cos

cbk1994 07-20-2010 08:12 PM

PHP Code:

temp.to = {3232};
temp.angle getangle(player.to[0], player.to[1]);
player.+= sin(angle);
player.-= cos(angle); 

like Loriel said, play with the signs until it works.

Loriel 07-20-2010 08:16 PM

otoh if you know the destination you can just take the vector to there, normalise it and then multiply it with how far you want to move

distx = 32 - player.x;
disty = 32 - player.y;
sqrtdist = sqrt(distx^2 + disty^2);
dx = r * distx / sqrtdist;
dy = r * disty / sqrtdist;

Jiroxys7 07-20-2010 09:18 PM

Thanks guys, I think I've got it working now :)


All times are GMT +2. The time now is 10:38 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.