Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Scripty mathy stuff (https://forums.graalonline.com/forums/showthread.php?t=66943)

Yen 06-26-2006 01:13 AM

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.

Giltwist2k1 06-27-2006 04:14 AM

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?

Yen 06-27-2006 06:48 PM

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.

Giltwist2k1 06-27-2006 07:55 PM

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.

calani 07-06-2006 01:43 AM

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.

Novo 07-06-2006 02:26 AM

It's called Mechanics 101. Take it.

Luigi203 07-06-2006 04:34 AM

Quote:

Originally Posted by Novo
It's called Mechanics 101. Take it.

How about bringing some PRODUCTIVITY to your posts?

Novo 07-06-2006 04:56 AM

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.

Novo 07-07-2006 03:19 AM

A small error in the above while rereading...


fx and fy weren't taken in consideration that partial power due to the zangle. :)

Novo 07-07-2006 07:02 AM

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.


All times are GMT +2. The time now is 06:15 PM.

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