GameMaker [SOLVED] how to make an object rotate another

M

Meve

Guest
Heya!
Back again with some questions coming from a not-so-skilled programmer:

So, basically I want a certain object (point_obj) to rotate another object (ship_blue_obj) if it is idle.
I have this code set up:
Code:
with (point_obj)
{

if collision_circle(ship_blue_obj.x,ship_blue_obj.y,10,point_obj,true,true)
= noone
{
    move_towards_point( ship_blue_obj.x, ship_blue_obj.y, 4 );
}
else
{
    //something to make it float around the ship
}
}
However, I don't know would fit my needs, maybe a quadratic function or something, or is there actually an existing function for this in gamemaker?
 
D

Danei

Guest
An easy way to achieve a basic orbit (assuming that's what you want, and not an object causing another to rotate):
Code:
///step event
 //if orbiting
orbitAngle = (orbitAngle += 1) mod 360;

x = lengthdir_x(desiredDistance + x,orbitAngle);
y = lengthdir_y(desiredDistance + y,orbitAngle);
Note that you'll need to tweak it so you're setting orbitAngle to the correct value when it reaches the ship and begins to orbit

Edit: forgot to put the current x and y in the functions
 
Last edited by a moderator:
What you could do is use the lengthdir_x and lengthdir_y! They have parameters called len, and dir that you can use...
Underneath // something to make it float around the ship, try using this statement.
// CREATE EVENT
rot = 0;
dist = 96; // How far you want it be from your object...
rot_spd = 10; // However fast you want it to rotate.

// STEP EVENT
rot += rot_spd;

if ( instance_exists( point_obj ) ) {
x = lengthdir_x( point_obj.x + dist, rot );
y = lengthdir_y( point_obj.y + dist, rot );
}
 
Top