Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-17-2003, 05:42 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
angle of player

I've been trying to script a kind of vortex that pulls with a spiraling effect. I've been able to get around several problems, but I just hit a wall. The problem is I don't know how to get the players angle. Someone suggested using getangle, but I don't quite know how it works very well. Another person sent me a whole mess of equations, which I doubt would work, but if it were to I wouldn't know the right function for inverse tangent.

first person said:
angle = getangle(playerx-centerx,playery-centery)

second person said:
prime = tan-((playery-centery)/(playerx-centerx));
if ((playerx-centerx)>=0 && (playery-centery)>=0) {angle = prime;}
if ((playerx-centerx)<=0 && (playery-centery)>=0) {angle = 180 - prime;}
if ((playerx-centerx)<=0 && (playery-centery)<=0) {angle = 180 + prime;}
if ((playerx-centerx)>=0 && (playery-centery)<=0){ angle = 360 - prime;}

Does anyone have a clue as to so they can help me out a little?
Reply With Quote
  #2  
Old 08-17-2003, 05:53 AM
Mykel Mykel is offline
:o
Mykel's Avatar
Join Date: May 2002
Location: Canton, Ohio.
Posts: 5,526
Mykel has a spectacular aura about
Send a message via AIM to Mykel Send a message via MSN to Mykel
Re: angle of player

Quote:
Originally posted by jake13jake
I've been trying to script a kind of vortex that pulls with a spiraling effect. I've been able to get around several problems, but I just hit a wall. The problem is I don't know how to get the players angle. Someone suggested using getangle, but I don't quite know how it works very well. Another person sent me a whole mess of equations, which I doubt would work, but if it were to I wouldn't know the right function for inverse tangent.

first person said:
angle = getangle(playerx-centerx,playery-centery)

second person said:
prime = tan-((playery-centery)/(playerx-centerx));
if ((playerx-centerx)>=0 && (playery-centery)>=0) {angle = prime;}
if ((playerx-centerx)<=0 && (playery-centery)>=0) {angle = 180 - prime;}
if ((playerx-centerx)<=0 && (playery-centery)<=0) {angle = 180 + prime;}
if ((playerx-centerx)>=0 && (playery-centery)<=0){ angle = 360 - prime;}

Does anyone have a clue as to so they can help me out a little?
This is Kai/Giltwist zone. I will IM Giltwist the link.
__________________
(Married to Skyld)
Reply With Quote
  #3  
Old 08-17-2003, 05:59 AM
TribulationStaff TribulationStaff is offline
Registered User
Join Date: Jul 2003
Location: Pennsylvania
Posts: 368
TribulationStaff is on a distinguished road
Send a message via AIM to TribulationStaff
Quote:
angle = getangle(playerx-centerx,playery-centery)
I always forget, such that I need to play with it to figure it out. Anyway, because graal is weird and the y-axis is inverted from the cartesian plane, I believe you need centery-playery in teh second bit...*thinks* or was it you needed to use -sin? One way or the other.

As for the spiraling effect, well you are going to need to do some sort of += on the x and the y that is based upon teh angle from the center of the whirlpool. Yay trigonometry!

[edit] the second bit is rather inefficient, needing four versions when one would probably do[/edit]
__________________


Help me keep scripting
Reply With Quote
  #4  
Old 08-17-2003, 06:11 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
if (created) {
drawoverplayer;
dontblock;
centerx = 30.5;
centery = 32;
pull = .3;
timeout=.05;
}
if (timeout) {

//angle=??
radius=((playerx-centerx)^2+(playery-centery)^2)^.5;
x = centerx + sin(angle/180*pi)*radius;
y = centery + cos(angle/180*pi)*radius;

if (playerswimming){
if (playerx>centerx){playerx-=pull;}
if (playerx<centerx){playerx+=pull;}
if (playery>centery){playery-=pull;}
if (playery<centery){playery+=pull;}
}

This is the npc so far.
The only += and -= are going to be in the pull.
I haven't added the pull that is going to attract to the npc's x and y yet, but that's simple.
I also haven't put restrictions as to how wide of an area it affects, but that's simple too.
I want the angle to be playerangle+degrees... that's the one thing I'm stuck on.
If you're wondering why I'm using drawoverplayer and don't block, it's because I'm using an image to test the movements.
Reply With Quote
  #5  
Old 08-17-2003, 06:59 AM
TribulationStaff TribulationStaff is offline
Registered User
Join Date: Jul 2003
Location: Pennsylvania
Posts: 368
TribulationStaff is on a distinguished road
Send a message via AIM to TribulationStaff
It looks to me that the way you have it, you will get a diamond sort of motion.

[edit]
try something more like
NPC Code:

playerx+=-(distfromcenter)*(somesortofpower)sin(anglefromcen ter);
playery+=(distfromcenter)*(somesortofpower)cos(ang lefromcenter); //this might be -= (see earlier comments)


this has to do with the derivatives of sin and cos.
[/edit]
__________________


Help me keep scripting

Last edited by TribulationStaff; 08-17-2003 at 07:10 AM..
Reply With Quote
  #6  
Old 08-17-2003, 07:06 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
ugh... no... if the npc moves on it's own it won't give the desired effect. it will pull across, closeto, and inbetween. To give it the current effect that I want, the angle of the npc has to be relative to the player, and I don't know how to get the player's angle, which is my problem.
Reply With Quote
  #7  
Old 08-17-2003, 07:24 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally posted by jake13jake
ugh... no... if the npc moves on it's own it won't give the desired effect. it will pull across, closeto, and inbetween. To give it the current effect that I want, the angle of the npc has to be relative to the player, and I don't know how to get the player's angle, which is my problem.
just calculate the distance on the x and y axis and do a getangle?

dx = centerx - playerx;
dy = centery - playery;
angle = getangle(dx,dy)

that what ya mean?
Reply With Quote
  #8  
Old 08-17-2003, 07:31 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
already tried that, didnt work, tried again, didnt work again :*(
Reply With Quote
  #9  
Old 08-17-2003, 07:34 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally posted by jake13jake
already tried that, didnt work, tried again, didnt work again :*(
what exactly do you want the script to do, as in the effect of it
Reply With Quote
  #10  
Old 08-17-2003, 07:37 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
I want it to pull towards the center points, and I want it to use a spiral current to pull the player around while it's pulling inward to give it a whirlpool effect.
Reply With Quote
  #11  
Old 08-17-2003, 07:40 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
Um, find the vector parts of the player's position in regard to the center, then uset that to find the angle and the desired new pos of the player, then add the vector components to the player's pos to move them to the new pos... er, here

playerdx = playerx-centerx
playerdy = playery-centery
angle = getangle(playerdx,playerdy)
radius = (playerdx^2+playerdy^2)^.5
newposx = centerx+cos(angle+addangle)*(radius-subtractradius)
newposy = centery+sin(angle+addangle)*(radius-subtractradius)
dx = playerx-newposx
dy = playery-newposy
playerx+dx
playery+dy

[EDIT] forgot to make it go inwards [/EDIT]
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #12  
Old 08-17-2003, 07:50 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
woah, that does the same thing x,x... except for that last part, which I don't understand unless you meant.
playerx+=dx
playery+=dy
In that case it screws up even more.
Reply With Quote
  #13  
Old 08-17-2003, 08:40 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
*punches self in eye*
should be
dx = newposx - playerx
dy = newposy - playery

and prolly have to subtract the sinus of the angles, since as Gil said Graal's y grid is upside down in comparison to common grids

*goes back to the nullifying effects of tv*
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #14  
Old 08-17-2003, 08:52 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
and that does the same thing?? maybe theres a bug with getangle?
Reply With Quote
  #15  
Old 08-17-2003, 10:15 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
Oh, that reminds me, dont friggen cut-n-paste scripts.(!) It works fine if you were to use your own variables atleast.

I kinda figured that some of those variable names were screwy but I didn't say anything. Ohwell just use this as a reminder, shortcuts are bad mmkay.
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
Reply


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 10:52 AM.


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