Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-20-2010, 07:24 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
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?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #2  
Old 07-20-2010, 08:02 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Jiroxys7 View Post
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.
Reply With Quote
  #3  
Old 07-20-2010, 08:08 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
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
Reply With Quote
  #4  
Old 07-20-2010, 08:12 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #5  
Old 07-20-2010, 08:16 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
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;
Reply With Quote
  #6  
Old 07-20-2010, 09:18 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Thanks guys, I think I've got it working now
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:41 AM.


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