1
\$\begingroup\$

Below is a code that defines the values ​​that cause the sprite to start at the top of the object being orbited:

Create Event:

ballSin=1;
ballCos=0;

ballSinMode=true;
ballCosMode=false;

Below is a code that modifies the values ​​started in the previous code so that the sprite starts to rotate / orbit the object in a counterclockwise direction:

Step Event:

if(ballSinMode){
    ballSin-=0.05;
    
    if(ballSin==-1){
        ballSinMode=false;
    }
}else{
    ballSin+=0.05;
    
    if(ballSin==1){
        ballSinMode=true;
    }
}

if(ballCosMode){
    ballCos+=0.05;
    
    if(ballCos==1){
        ballCosMode=false;
    }
}else{
    ballCos-=0.05;
    
    if(ballCos==-1){
        ballCosMode=true;
    }
}

Draw Event:

draw_sprite(Sprite7,0,x+(75*ballCos),y+(-75*ballSin));

The object/sprite moves correctly, but the movement occurs as follows:

enter image description here

The movement I would like the object/sprite to perform:

enter image description here

I don't know why the object makes a straight movement. For me it would tend to always keep the same distance from the reference point (position of the object in the center). Since the movement is not circular, it does not. I would like to know why and how to make him move in the desired way.

OBS - Using the program's "path" feature is out of the question.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

The ballSin and ballCos basically says "move across the x/y axis", it's rather a misleading variable name. Because sin and cos has no relation with just the x and y axis. So be aware to not confuse yourself with it.

I've found some possible solution through a quick search, maybe you should try this out:

The Events below are meant for the red ball object, the square variable means the square object.

Create Event:

radius = point_distance(square.x, square.y, x, y);
phase = point_direction(square.x, square.y, x, y);

Step Event:

phase += 5; //you can change this to alter the speed/direction
x = square.x + radius * dcos(phase);
y = square.y - radius * dsin(phase);

Draw Event:

draw_sprite(Sprite7,0,x,y);

(Keep in mind that you should do an instance_exists(square) before checking for the object, else it'll crash.)

Source at: https://forum.yoyogames.com/index.php?threads/how-can-i-rotate-3-objects-around-a-central-point.11360/post-73795

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .