• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Make object orbiting around a point...[SOLVED]

A

AFD456

Guest
Hello everyone, I'm trying to code Throw Knife game like this one for example (https://play.google.com/store/apps/details?id=com.yxy.game.throwingknife). I found here great code for orbiting, which actually works. Instances of object oKnife are orbiting around a center of oTarget. But I have a one problem. It doesn't matter where I throw (mouse_click; touch the screen) the Knives. They just gather on the right side of the Target along its X axis. As you can see on the picture.

oKnife:
Code:
 Create Event:
 //Orbit = 200//300//400....
 Orbit = point_distance(x,y,oTarget.x, oTarget.y) // Orbit distance
 Angle = 0 // Current orbital angle
 Speed = 1 // Orbital speed
 Center_X = oTarget.x // x of orbital center
 Center_Y = oTarget.y // y of orbital center

Step event:
image_angle -= Speed
Angle -= Speed;
if(Angle >= 360) Angle -= 360;

// Update position
x = lengthdir_x(Orbit, Angle) + Center_X;
y = lengthdir_y(Orbit, Angle) + Center_Y;
oTarget
Code:
Create Event:

WheelDir = 0

Step Event:

WheelDir += 1 //Increase direction --> spinning the wheel

if WheelDir = 360{//Reset direction to 0 when a full turn is made
   WheelDir = 0;
}

Mouse Event for Left Pressed:
instance_create(mouse_x,mouse_y,oKnife)
 
Draw Event:

draw_sprite_ext(sprite_index,image_index,x,y,image_xscale,image_yscale,-WheelDir,image_blend,1)
Do you know how to fix it? Thank you for your time and answers!
 

Attachments

Last edited by a moderator:

obscene

Member
When you create the object at x,y, the very first thing you need to do is get the point_direction from the center of the wheel to x,y and set that as WheelDir.
 
A

AFD456

Guest
When you create the object at x,y, the very first thing you need to do is get the point_direction from the center of the wheel to x,y and set that as WheelDir.
Thank you for bringing me this idea.:)
And I found a solution:)
Code:
oKnife_Create_event

Orbit = point_distance(x,y,oSpin.x, oSpin.y) // Orbit distance
Angle = point_direction(x, y, oSpin.x, oSpin.y) - 180; // Current orbital angle
 
Last edited by a moderator:
Top