orbitActor() - Orbit any actor about a point or actor

How to find or create sprites, graphics, sounds and music.

orbitActor() - Orbit any actor about a point or actor

Postby GEuser » Tue May 06, 2014 3:59 am

DESCRIPTION

Make any actor orbit a given coordinate or around another actor (whether canvas, normal, wire frame region or fill region).

BASIC INFORMATION

void orbitActor (Actor *theActor, double orbStep, int orient, double cenX, double cenY, double radius)

theActor - The Actor that does the orbitting. Use ampersand with your actor name to use in function [ e.g. orbitActor ( &yourActorName,... ) ]

orbStep - The incremental step for your orbit in degrees (e.g. 0.5 will advance by half a degree each time you call the function).

orient - The orientation for your orbit. 1 = Orbit clockwise, -1 = Orbit anti-clockwise.

cenX, cenY - The central point about which your actor will orbit. This can be any x,y coordinate or x,y position of another actor.

radius - The distance in pixels from the central point set by cenX & cenY.


CODE USAGE

1. Create an actor variable with a real value, call it: orbAngle.
(script > Global Code > Variables > ADD. Click Name > type: orbAngle. Click Integer > select Real, Click Global > select Actor variable, Click ADD).

2. Add the global code below as orbitActor (or whatever you want).

Code: Select all
void orbitActor (Actor *theActor, double orbStep, int orient, double cenX, double cenY, double radius)
{
    double dx=0.0; double dy=0.0;
 
    orbAngle+=orbStep; orient*=-1;
    dx=radius*orient*sin(degtorad(orbAngle)); dy=radius*cos(degtorad(orbAngle));
 
    theActor->x=dx+cenX;
    theActor->y=dy+cenY;
 
    if(orbAngle>359){ orbAngle=0; }
    if(orbAngle<0){ orbAngle=359; }
}


3. Create your actors and call the orbitActor() function.

EXAMPLE

Got 2 actors, TEST1 & TEST2.

When space key pressed make TEST2 orbit TEST1. Make TEST1 orbit point x=50, y=50.
Advance orbit by 1 degree steps clockwise. TEST2 at 50 & TEST1 at 100 pixel distance.

SPACE KEY down event of TEST1:
Code: Select all
 orbitActor(&TEST1, 1, 1, 50, 50, 100);


SPACE KEY down event of TEST2:
Code: Select all
orbitActor(&TEST2, 1, 1, TEST1.x, TEST1.y, 50);


* You can make any type of actor orbit any point or any actor, whether they are fill/wire regions, canvas or normal.
* Remember to put the "&" in front of the actor you use in the orbitActor function.
Last edited by GEuser on Fri May 16, 2014 3:13 pm, edited 1 time in total.
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score

Re: orbitActor() - Orbit any actor about a point or actor

Postby Jagmaster » Fri May 09, 2014 12:11 am

This should be one of those helper functions that's packed with GE.
Seriously, I always hated messing around with trigonometric functions to get actors to orbit and stuff
(To tell you the truth, I didn't understand the sine and cosine's usefulness until I had to use it in some scripts.)
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: orbitActor() - Orbit any actor about a point or actor

Postby GEuser » Fri May 16, 2014 3:17 pm

Jagmaster wrote:This should be one of those helper functions that's packed with GE.
Seriously, I always hated messing around with trigonometric functions to get actors to orbit and stuff
(To tell you the truth, I didn't understand the sine and cosine's usefulness until I had to use it in some scripts.)


Th newer version handles this stuff well but I'm still using older 1.4.0 version because I use Linux.

[EDIT] Removed the "]" bracket typo and correctly replaced with the ";" in the SPACE KEY event codes.
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score


Return to Game Resources

Who is online

Users browsing this forum: No registered users and 1 guest

cron