Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Particle Effects->revolving around a set point. (https://forums.graalonline.com/forums/showthread.php?t=83098)

Vulgar 12-10-2008 06:07 PM

Particle Effects->revolving around a set point.
 
Ok, I have been trying to figure out how to make particles revolve around a player or a set point like lets say a lamp. I have been looking around and haven't been able to find anything that will explain how I can accomplish this. I have been out of school for a few years now and I totally forgot how sin cos and tan are used so I don't know if I would need to use those to accomplish it. If someone could point me in the right direction that would be awesome.

xXziroXx 12-10-2008 06:39 PM

Do you mean just spinning around a set point, or like, spinning around while going infront and behind the player? Not that I'd be able to help with either, just trying to clarify it..

Vulgar 12-10-2008 06:44 PM

I can make it so it will go behind the player but I just cant make it actually rotate around the player. Like pretend the the player is the sun and that I want earth to revolve around me. Like in a circle not like from front to back.

Chompy 12-10-2008 08:03 PM

You'd have to time events like when it has travelled 180 degrees around the target then make the layer increase. Just alter the layer of the particles when it has traveled 180 degrees around to player or from <x1,y1> to <x2,y2> (from the left side of the player to the right side of the player for example)

To sum it up: Edit the particles' layer.

Vulgar 12-11-2008 04:36 AM

That's not what I mean, I know how to use layers. but i want it to rotate in a circle. Like if you know what Zodiac's Dark Knight skill Shadow Swipe looks like, or Endoras old targeting system or even malorias old targeting system. i want it to move in a circle. I pretty much want to be able to make a ring out of light2.png.

Sage_Shadowbane 12-11-2008 08:21 AM

You would most likely have to use sin/cos (which i'm not too familiar with myself.) and alter the x/y of the particle in a timeout loop is what im guessing. Im sure someone here could help you to figure out how exactly you would use sin/cos to create a 360 degree radius. Anyone feel like helping this here feller?! :confused:

Vulgar 12-11-2008 01:01 PM

Yeah, that's what I'm talking about I totally fail when it comes to math. If anyone could point me in right direction that would be awesome. I don't know anything about sin/cos/tan.

DrakilorP2P 12-11-2008 03:00 PM

This is basic trigonometry; just read about it on Wikipedia and you'll figure it out.

When you're done, read below for answer.

Spoiler alert:
x = cos(a) * r
y = sin(a) * r

Loriel 12-11-2008 04:17 PM

Quote:

Originally Posted by Vulgar (Post 1448378)
Like pretend the the player is the sun and that I want earth to revolve around me.

The gravitational force works like this: http://londeroth.org/tex/\vec G(\vec...M}{r^2} \hat r, with the gravitational constant http://londeroth.org/tex/\Gamma = 6....g}\,\mbox s^2}, the masses http://londeroth.org/tex/m and http://londeroth.org/tex/M of the two bodies and the distance http://londeroth.org/tex/\vec r between them.

For a stable orbit you need to achieve a constant state of freefall, where the gravitation only impacts the direction of the orbitting body's velocity, ie it acts as the centripetal force http://londeroth.org/tex/F = \frac{m \cdot v^2}{r}. It has to be orthogonal to the direction of the velocity of the body anyway, so we can examine this as a one-dimensional problem.

We obtain http://londeroth.org/tex/F = G \Left...m\cdot M}{r^2}. You basically just need to write up an engine that applies the gravitational force to the velocity each timestep http://londeroth.org/tex/\Delta t = 0.05\,\mbox{s}, then solve for http://londeroth.org/tex/v to determine the required speed for the orbitting body at the desired distance after inserting the masses of both.

Here is a sample implementation of two numerical approaches to solving differential equations, perhaps it could help you:

PHP Code:

#include <iostream>
#include <ostream>
#include <fstream>
#include <cmath>

#include "common.hpp"

int main() {
  
using std::sqrt;
  
using prog::pow;

  
// Euler
  
{
    
double x 1;
    
double y 0;
    
double x_ 0;
    
double y_ 0.75;
    
double t  0;
    const 
double dt 1.0/100;
    
int i 0;
    
std::ofstream out("euler_log");

    while (
10) {
      const 
double last_y y;
      const 
double last_x x;

      
+= dt;

      
+= dt x_;
      
+= dt y_;

      
x_ += dt * -1/pow<3>(sqrt(pow<2>(last_x)+pow<2>(last_y))) * last_x;
      
y_ += dt * -1/pow<3>(sqrt(pow<2>(last_x)+pow<2>(last_y))) * last_y;

      
out << << ' ' << << ' ' << << ' ' << x_ << y_ << '\n';
      if (
last_y 0) {
        ++
i;
        
std::cout
         
<< "x   = " << << "\n"
            "y   = " 
<< << "\n"
            "E   = " 
<< ((x_*x_+y_*y_)/2-1/sqrt(pow<2>(x)+pow<2>(y))) << "\n"
            "L_z = " 
<< (x*y_ y*x_) << '\n' << std::endl;
      }

    }
    
system("gnuplot -persist euler_plot");
  }
  
// Runge-Kutta
  
{
    
double x 1;
    
double y 0;
    
double x_ 0;
    
double y_ 0.75;
    
double t  0;
    const 
double dt 1.0/100;
    
int i 0;
    
std::ofstream out("runge-kutta_log");

    while (
10) {
      const 
double last_y y;

      
+= dt;

      const 
double k1_x  x_;
      const 
double k1_y  y_;

      const 
double k1_x_ = -1/pow<3>(sqrt(pow<2>(x)+pow<2>(y)))*x;
      const 
double k1_y_ = -1/pow<3>(sqrt(pow<2>(x)+pow<2>(y)))*y;

      const 
double k2_x  x_ dt/2*k1_x_;
      const 
double k2_y  y_ dt/2*k1_y_;

      const 
double k2_x_ = -1/pow<3>(sqrt(pow<2>(x+dt/2*k1_x)+pow<2>(y+dt/2*k1_y)))*(x+dt/2*k1_x);
      const 
double k2_y_ = -1/pow<3>(sqrt(pow<2>(x+dt/2*k1_x)+pow<2>(y+dt/2*k1_y)))*(y+dt/2*k1_y);

      const 
double k3_x  x_ dt/2*k2_x_;
      const 
double k3_y  y_ dt/2*k2_y_;

      const 
double k3_x_ = -1/pow<3>(sqrt(pow<2>(x+dt/2*k2_x)+pow<2>(y+dt/2*k2_y)))*(x+dt/2*k2_x);
      const 
double k3_y_ = -1/pow<3>(sqrt(pow<2>(x+dt/2*k2_x)+pow<2>(y+dt/2*k2_y)))*(y+dt/2*k2_y);

      const 
double k4_x  x_ dt*k2_x_;
      const 
double k4_y  y_ dt*k2_y_;

      const 
double k4_x_ = -1/pow<3>(sqrt(pow<2>(x+dt*k3_x)+pow<2>(y+dt*k3_y)))*(x+dt*k3_x);
      const 
double k4_y_ = -1/pow<3>(sqrt(pow<2>(x+dt*k3_x)+pow<2>(y+dt*k3_y)))*(y+dt*k3_y);

      
x_ x_ dt/6*(k1_x_+2*k2_x_+2*k3_x_+k4_x_);
      
y_ y_ dt/6*(k1_y_+2*k2_y_+2*k3_y_+k4_y_);

      
dt/6*(k1_x+2*k2_x+2*k3_x+k4_x);
      
dt/6*(k1_y+2*k2_y+2*k3_y+k4_y);


      
out << << ' ' << << ' ' << << ' ' << x_ << y_ << '\n';
      if (
last_y 0) {
        ++
i;
        
std::cout
         
<< "x   = " << << "\n"
            "y   = " 
<< << "\n"
            "E   = " 
<< ((x_*x_+y_*y_)/2-1/sqrt(pow<2>(x)+pow<2>(y))) << "\n"
            "L_z = " 
<< (x*y_ y*x_) << '\n' << std::endl;
      }

    }
    
system("gnuplot -persist runge-kutta_plot");
  }



Vulgar 12-11-2008 07:26 PM

*headache*

Admins 12-11-2008 07:58 PM

There is TShowImg.spin which helps for most cases, if you do emitter.attachposition = true then it will also automatically rotate the emitted particles. If you just want that the particles are emitted in a ring then change emitter.emissionoffset = {cos(timevar2)*5, -sin(timevar2)*5, 0} or so in a timeout

Vulgar 12-11-2008 08:46 PM

Thanks for the replys, I can't seem to figure out the sin and cos and I don't like using things that I don't understand. Although I have accomplished what I was trying to do with this
NPC Code:
emitter.addlocalmodifier("range", 0, 1, "angle", "replace", -3, 3);

but I was wondering if there was anyway to make the effect instant instead of waiting for all the particles to loop around.

DarkReaper0 12-12-2008 02:14 AM

Eh, basic circle script equations when you want to solve for x and y positions:
PHP Code:

centerx r*cos(A);
centery r*sin(A);

//Obviously center x and center y would be your coordinates.

//A stands for alpha and should basically just be increased by .05 each run
//through, basically 'a += .05;'

//And r stands for the radius of your circle 


WhiteDragon 12-12-2008 04:48 AM

Quote:

Originally Posted by Loriel (Post 1448670)
Here is a sample implementation of two numerical approaches to solving differential equations, perhaps it could help you:

I don't think more than 3 people on this forum would understand a 4th order runge-kutta. >.>

Loriel 12-12-2008 02:10 PM

Quote:

Originally Posted by WhiteDragon (Post 1448847)
I don't think more than 3 people on this forum would understand a 4th order runge-kutta. >.>

I sure did not get it right until the guy running the lecture went ahead and explained it to me :v


All times are GMT +2. The time now is 05:11 AM.

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