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 12-10-2008, 06:07 PM
Vulgar Vulgar is offline
()
Vulgar's Avatar
Join Date: May 2008
Location: Chesapeake, Virginia
Posts: 59
Vulgar is an unknown quantity at this point
Send a message via AIM to Vulgar
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.
__________________
.
Reply With Quote
  #2  
Old 12-10-2008, 06:39 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
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..
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #3  
Old 12-10-2008, 06:44 PM
Vulgar Vulgar is offline
()
Vulgar's Avatar
Join Date: May 2008
Location: Chesapeake, Virginia
Posts: 59
Vulgar is an unknown quantity at this point
Send a message via AIM to Vulgar
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.
__________________
.
Reply With Quote
  #4  
Old 12-10-2008, 08:03 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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.
__________________
Reply With Quote
  #5  
Old 12-11-2008, 04:36 AM
Vulgar Vulgar is offline
()
Vulgar's Avatar
Join Date: May 2008
Location: Chesapeake, Virginia
Posts: 59
Vulgar is an unknown quantity at this point
Send a message via AIM to Vulgar
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.
__________________
.
Reply With Quote
  #6  
Old 12-11-2008, 08:21 AM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
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?!
Reply With Quote
  #7  
Old 12-11-2008, 01:01 PM
Vulgar Vulgar is offline
()
Vulgar's Avatar
Join Date: May 2008
Location: Chesapeake, Virginia
Posts: 59
Vulgar is an unknown quantity at this point
Send a message via AIM to Vulgar
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.
__________________
.
Reply With Quote
  #8  
Old 12-11-2008, 03:00 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
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
__________________
Testbed user: I figured since I can never find any scripters it was time to take desperate measures...and...TEACH MYSELF 0.0
Reply With Quote
  #9  
Old 12-11-2008, 04:17 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Vulgar View Post
Like pretend the the player is the sun and that I want earth to revolve around me.
The gravitational force works like this: , with the gravitational constant , the masses and of the two bodies and the distance 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 . 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 . You basically just need to write up an engine that applies the gravitational force to the velocity each timestep , then solve for 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");
  }

Reply With Quote
  #10  
Old 12-11-2008, 07:26 PM
Vulgar Vulgar is offline
()
Vulgar's Avatar
Join Date: May 2008
Location: Chesapeake, Virginia
Posts: 59
Vulgar is an unknown quantity at this point
Send a message via AIM to Vulgar
*headache*
__________________
.
Reply With Quote
  #11  
Old 12-11-2008, 07:58 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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
Reply With Quote
  #12  
Old 12-11-2008, 08:46 PM
Vulgar Vulgar is offline
()
Vulgar's Avatar
Join Date: May 2008
Location: Chesapeake, Virginia
Posts: 59
Vulgar is an unknown quantity at this point
Send a message via AIM to Vulgar
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.
__________________
.
Reply With Quote
  #13  
Old 12-12-2008, 02:14 AM
DarkReaper0 DarkReaper0 is offline
No.
DarkReaper0's Avatar
Join Date: May 2005
Location: Texas,USA
Posts: 344
DarkReaper0 will become famous soon enough
Send a message via MSN to DarkReaper0
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 
Reply With Quote
  #14  
Old 12-12-2008, 04:48 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Loriel View Post
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. >.>
Reply With Quote
  #15  
Old 12-12-2008, 02:10 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by WhiteDragon View Post
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
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 02:44 PM.


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