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 06-26-2006, 01:13 AM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
Scripty mathy stuff

My head hurts.
Someone help me with this, or even work it out for me. ;-;

verticalspeed = sin(zangle)*s
verticalspeed -= .1 every .05 seconds
horizontalspeed = cos(zangle)*s
x = x + cos(angle)*horizontalspeed
y = y - sin(angle)*horizontalspeed
z = z + verticalspeed

zangle = -pi/10
initial z = 8
initial x = 0
initial y = 0

I need it so when z = 0, x,y = finalx,finaly
z = 0, x = finalx, y = finaly

;-; Help.
Reply With Quote
  #2  
Old 06-27-2006, 04:14 AM
Giltwist2k1 Giltwist2k1 is offline
Registered User
Giltwist2k1's Avatar
Join Date: Jun 2002
Posts: 13
Giltwist2k1 is on a distinguished road
Send a message via ICQ to Giltwist2k1 Send a message via AIM to Giltwist2k1 Send a message via Yahoo to Giltwist2k1
Aroo? Could you tell me what you are trying to do? Make a custom projectile NPC? Doesn't Graal have a built in system for dealing with a 3rd dimension? Why are you going crazy with this stuff?
Reply With Quote
  #3  
Old 06-27-2006, 06:48 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
It's the formulas(ae?) for the built-in projectile's movement.
I need a formula so that it lands on the position I want it to..

The main problem is that I don't want it to go up and then down.
I just want it to go down.
Reply With Quote
  #4  
Old 06-27-2006, 07:55 PM
Giltwist2k1 Giltwist2k1 is offline
Registered User
Giltwist2k1's Avatar
Join Date: Jun 2002
Posts: 13
Giltwist2k1 is on a distinguished road
Send a message via ICQ to Giltwist2k1 Send a message via AIM to Giltwist2k1 Send a message via Yahoo to Giltwist2k1
So you don't really care what angle it's shot at so long as it lands in the right place and only goes down? You might be better off with algebraic parabolic motion than the trigonometry approach.
Reply With Quote
  #5  
Old 07-06-2006, 01:43 AM
calani calani is offline
Scriptess
calani's Avatar
Join Date: Aug 2003
Location: asmgarden.gmap
Posts: 606
calani is on a distinguished road
Send a message via AIM to calani
I've puzzled over this for awhile and eventually gave up.
At the time I didn't -need- it (was making a flak cannon-like thing on Archaic. instead of picking 7 xy's and doing it from there, i just did random angles and speeds)

though, you could do a getangle to find the xy angle. that's the easy one.
with the z angle, there's a whole line of possibilities - different zangles and different speeds.
you could find working zangle and speeds using trial-and-error and testing to see if the distance works out (and possibly limit your search to a certain range of angles or speeds to make the result look decent) with a formula somewhat like this pseudo-code one:
projectile_distance=projectile_speed*ticks_before_ impact
you could find ticks with the cosine of the zangle times projectile speed and divide that by your gravity (since its a static reduction)

somewhat like that would work (though i bet i confused you even more with that)



now go get some advil for your [new] headache.
__________________
Reply With Quote
  #6  
Old 07-06-2006, 02:26 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
It's called Mechanics 101. Take it.
Reply With Quote
  #7  
Old 07-06-2006, 04:34 AM
Luigi203 Luigi203 is offline
Hamma Time
Luigi203's Avatar
Join Date: Mar 2003
Location: North East PA
Posts: 285
Luigi203 is on a distinguished road
Send a message via AIM to Luigi203
Quote:
Originally Posted by Novo
It's called Mechanics 101. Take it.
How about bringing some PRODUCTIVITY to your posts?
__________________


CAUTION
Reply With Quote
  #8  
Old 07-06-2006, 04:56 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Luigi203
How about bringing some PRODUCTIVITY to your posts?
Not allowed linking to external sites!

Quote:
verticalspeed = sin(zangle)*s
verticalspeed -= .1 every .05 seconds
horizontalspeed = cos(zangle)*s
x = x + cos(angle)*horizontalspeed
y = y - sin(angle)*horizontalspeed
z = z + verticalspeed

zangle = -pi/10
initial z = 8
initial x = 0
initial y = 0

I need it so when z = 0, x,y = finalx,finaly
z = 0, x = finalx, y = finaly
Solve for T:
PHP Code:
fy vt 1/gt^2
gt
In the case of Graal
With v decreasing every 0.05 seconds of 0.1... It means the velocity is...

v = sin(zangle)*power + 2t

Now...

PHP Code:
v(0)1/g(0)t^2
sin(zangle)*power t^
Using the Pythagreom Theorum:
PHP Code:
= (-+- (b^4AC)^0.5)/2A
= (-sin(zangle)*power +- ((sin(zangle)*power)^4*y)^0.5)/2
This gives you two t's... Usually, there are two ways to reach a point using this... One is going very high up, and falling short... Or... Going very low, and very far... The higher up one takes longer for the same location ( more distance to cover ).

Now that you got t...

You can solve your location you want by...

PHP Code:
fx sin(angle)*t
fy 
cos(angle)*
But! Because Graal coordinates go from 0 to 64, and no 64 to 0... It means your grid is inversied...

PHP Code:
fy cos(angle)*
=] And you know where the projectile should land....


This is inaccurate in the sense that the speed is decreased only every 0.05 seconds, and so, the accelleration is actually an step-function. This means that for the period of 0-0.05, it decreases in an instance, rather than gradually, like in real life. It also means that it has the possibility to be off, but... Not by much.


; That's off the top of my head. I didn't check if I made mistakes.

Last edited by Novo; 07-06-2006 at 05:14 AM..
Reply With Quote
  #9  
Old 07-07-2006, 03:19 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
A small error in the above while rereading...


fx and fy weren't taken in consideration that partial power due to the zangle.
Reply With Quote
  #10  
Old 07-07-2006, 07:02 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Alright... I just made something for this... Anyhow... I was working on Projectiles for Relic, and I have encountered problems with the shoot as well...

After several hours of working on it... I found out the that gravity laws don't work. The reason for this is that the verticle speed, or the horizontal speed... Aren't in tiles per second, but rather in tiles per 0.05 seconds. This implies that if you had a power of 1, and you're going maximum distance, you go 20 tiles, rather than 1 tile..

distance = (v^2 * sin(2 * zangle ) ) / gravity

So when Power == 1, and gravity == 1... Distance would give 1...

But, if you make adjustments to the values, and treat them as per 0.05 seconds... Everything falls into place:

Final Code:

PHP Code:
function onMouseDownbutton )
  {
  
gravity 0.8;
  
temp.power 1;

  
temp.maxdist = ( (temp.power*20) ^ ) / (gravity 20);
  
temp.dist = ((mousex player.x)^+ (mousey player.y)^2)^0.5;
  if ( 
temp.dist temp.maxdist )
    
temp.dist temp.maxdist;

  
temp.zangle arcsintemp.dist * (gravity*20) / ( (temp.power*20) ^ 2) ) / 2;
  if ( 
button == "double" )
    
temp.zangle = (pi 2) - temp.zangle;

  
temp.getanglemousex 1.5 player.xmousey 2  player.);
  
shootplayer.x,player.y,player.2temp.atemp.zangletemp.power"arrow","");
  }

function 
arcsin)
  { 
// Missing arcsin function, so I made one myself!
  
temp.step 1000;
  for ( 
0abs(i); += temp.step )
    
temp.sum += (/ (j^2)^0.5) * temp.step ;
  return 
temp.sum;
  } 
=] I hope this solves a lot of anguish.
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 08:51 PM.


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