Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   'Power' parameter in the shoot command (https://forums.graalonline.com/forums/showthread.php?t=57087)

ApothiX 01-16-2005 02:59 AM

'Power' parameter in the shoot command
 
I am attempting to create a projectile using the 'zangle' and 'power' parameters of the 'shoot' command, something like the bows on Graal Kingdoms. My problem is that I cannot find out the equation for 'power' based on the distance you want the projectile to be launched. I'm using a zangle of pi/4.

Any help would be much appreciated. (Please do not simply say "search the forums", as I have done so, but every conversation I've seen about the zangle in the shoot command has ended abruptly before 'power' was touched.)


Thanks,
Okiesmokie

Sildae 01-16-2005 03:24 AM

Use a loop to test increasing powers simulating shoot, until you have found one that works for the distance.

Evil_Trunks 01-16-2005 04:11 AM

Quote:

Originally Posted by Sildae
Use a loop to test increasing powers simulating shoot, until you have found one that works for the distance.

sike, that's a terrible way

just calculate the projectile physics, like i did

v = dt
d=1/2at^2 + vit

simultaneous equations, or whatever it's called, the time is the same in both equations (well, the time is double in the v=dt equation)

the information about projectile movement can be found in newfeatures.txt

i used a constant zangle of 45 degrees

i could just post you the entire script but that might be against the rules?

ApothiX 01-16-2005 07:01 AM

Quote:

Originally Posted by Evil_Trunks
just calculate the projectile physics, like i did

v = dt
d=1/2at^2 + vit

What does the 'i' variable represent?


Quote:

Originally Posted by Evil_Trunks
the information about projectile movement can be found in newfeatures.txt

I saw that information, But I don't have a strong enough hold on physics and whatnot to be able to get the equation for power out of it. :(


Quote:

Originally Posted by Evil_Trunks
i used a constant zangle of 45 degrees

That's what pi/4 is, I think.


Quote:

Originally Posted by Evil_Trunks
i could just post you the entire script but that might be against the rules?

Only the shoot command, or the place where you calculate power is really required.

Evil_Trunks 01-16-2005 07:03 AM

Quote:

Originally Posted by ApothiX
What does the 'i' variable represent?

vi, it stands for initial velocity, i was thinking i should have clarified this but i didn't for some reason...

Quote:

Originally Posted by ApothiX
Only the shoot command, or the place where you calculate power is really required.

you really sort of need to have taken physics to understand how to solve this

i didn't simplify any of the stuff that could be simplified

NPC Code:
this.power = ( ( this.dist * -0.1 ) / ( 2 * cos(this.zangle)  * -1 * sin(this.zangle) ) ) ^ 0.5;



you will probably want to offset your destination x y by -1.5 or something, since projectiles have a width/height of 48x48

otherwise the top left corner will land at the coordinates you used (i think)


here is the information I used, by the way, taken from newfeatures
(actually someone pasted it into the #gscript channel)
Quote:

Projectiles are easy to use and don't take a lot of bandwidth because only
the shooting of the projectile needs to be sent, the movement is calculated on
the different computers. The projectile is flying like a heavy object thrown
through the air: the horizontal movement speed keeps the same (moves
horzspeed=cos(zangle)*speed tiles all 0.05 seconds), the vertical speed is
initialized as vertspeed=sin(zangle)*speed and is decreased by 0.1 all 0.05 seconds;
then the new position (calculated all 0.05 seconds) is
newx = x + cos(angle)*horzspeed, newy = y - sin(angle)*horzspeed,
newz = z + vertspeed
I found this file where I saved my work
Quote:

Originally Posted by work
vertical

Vi = vertspeed = sin(zangle)*speed [tiles / 0.05 secs]
acceleration = -0.1 [tiles / 0.05 secs ^2]
Vf = 0
time = ? [0.05 secs]
Vf = Vi + at
t = ( Vf - Vi ) / a

horizontal

v = horzspeed = cos(zangle)*speed [tiles/ 0.05 secs]
d = distance [tiles]
t = ? [0.05 secs]
d=vt
t = d/v

combo

d/v = 2 * ( Vf - Vi ) / a
dist / ( cos(zangle)*speed ) = 2 * ( 0 - sin(zangle)*speed ) / -0.1
dist * -0.1 = 2* ( cos(zangle)*speed ) * ( 0 - sin(zangle)*speed )
dist * -0.1 = 2* cos(zangle) * speed ^ 2 * -1 * sin(zangle)
speed = ( ( dist * -0.1 ) / ( 2 * cos(zangle) * -1 * sin(zangle) ) ) ^ 0.5

Stefan uses speed to say power in the newfeatures explanation

ApothiX 01-16-2005 08:56 AM

Thank you very much, your solution worked perfectly :)

The thing that threw me off was the 'speed' in newfeatures, I didn't know that meant power x_x

Projectshifter 01-16-2005 08:22 PM

Quote:

Originally Posted by Evil_Trunks
i used a constant zangle of 45 degrees

I highly doubt you did 45 degrees considering these is based off of radians...
pi/4 is the radian equivalent of 45 degrees.

The rest is just basic physics calculations. I haven't played with the shoot command much, but if it follows basic physics principles then all the equations stated should work out.


All times are GMT +2. The time now is 04:54 AM.

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