Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   angle of player (https://forums.graalonline.com/forums/showthread.php?t=47214)

jake13jake 08-17-2003 05:42 AM

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?

Mykel 08-17-2003 05:53 AM

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.

TribulationStaff 08-17-2003 05:59 AM

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]

jake13jake 08-17-2003 06:11 AM

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.

TribulationStaff 08-17-2003 06:59 AM

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]

jake13jake 08-17-2003 07:06 AM

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.

Python523 08-17-2003 07:24 AM

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?

jake13jake 08-17-2003 07:31 AM

already tried that, didnt work, tried again, didnt work again :*(

Python523 08-17-2003 07:34 AM

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

jake13jake 08-17-2003 07:37 AM

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.

Dach 08-17-2003 07:40 AM

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]

jake13jake 08-17-2003 07:50 AM

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.

Dach 08-17-2003 08:40 AM

*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*

jake13jake 08-17-2003 08:52 AM

and that does the same thing?? maybe theres a bug with getangle?

Dach 08-17-2003 10:15 AM

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.

jake13jake 08-17-2003 10:26 AM

that would be much easier if i knew what subtractradius and addangle were meant to be x,x

Dach 08-17-2003 10:31 AM

meh, I set them as .1, you can mess around with them till you get the right effect, ima go sleepy time now, ... ...

Kaimetsu 08-17-2003 11:43 AM

I wouldn't use angles at all, personally. It's so much easier if you just form a vector with two components: one pointing into the centre (the pull effect) and one perpendicular to that (the spiral effect).

TribulationStaff 08-17-2003 07:25 PM

Most Graalians don't know about vectors, so I figured I would suggest the simplest answer.

For those of you who don't know, a vector is an arbitrary motion through a plane or through a field. Where it starts doesn't matter. all a vector tells you is where you are going. They are often written in the notation <dx,dy>

So the vector <1,3> could move something from (0,0) to (1,3), but it would be the same vector if it moved something from (8,2) to (9,5)

In Kai's solution, you need two vectors. The first moves the player around the circumference of the circle. The second moves the player towards the center of the circle.

[edit] After rereading Kai's post, I see that he is being clever and using a vector that is orthagonal to the first. That dependance upon the pull vector allows for the removal of trigonometry[/edit]

Dach 08-17-2003 10:33 PM

Quote:

Originally posted by Kaimetsu
I wouldn't use angles at all, personally. It's so much easier if you just form a vector with two components: one pointing into the centre (the pull effect) and one perpendicular to that (the spiral effect).
HOLY ****E I GET IT NOW!!!!

thanks Kai, *runs off to kill sinus and cosinus crap*

SaijinGohan 08-17-2003 10:59 PM

I would just pull the player and make a gani of the player spinning. lol

Neoreno 08-17-2003 11:27 PM

I believe he wants the player to spiral round a point, not the player spinning.

jake13jake 08-18-2003 08:28 AM

Maybe if I took the equation for the x and y and replaced x and y with playerx and playery and angle with playerangle and solved for playerangle? Doing this I get stuck at what to do when I have to take out of the function because I forgot all of my math classes over summer break.

Where I'm at though:
(playerx-centerx)/radius = sin(playerangle/180*pi)
(playery-centery)/radius = cos(playerangle/180*pi)

can anyone help out?

jake13jake 10-07-2003 03:15 AM

woah-ness.... I finally figured it out... it turned out that it had to be:
dy = centerx-playerx;
dx = playery-centery;

yea... i think that the playery-centery inversion is kindof wierd... as well as the x's going under dy and the y's going under dx... BUT I JUST HAD TO FOOL AROUND WITH IT A LIL'... god... 2 months of heavy... heavy thinking and I FINALLY get it...

Now just to mess with the pull scripts.

Kaimetsu 10-07-2003 04:39 AM

Trying random things until it works is not "heavy thinking" :\

Dach 10-07-2003 04:57 PM

that's funny, cause whatever I made then worked


All times are GMT +2. The time now is 09:11 PM.

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