GML [SOLVED] Track angle dif for drag and swing sword

N

noobhere

Guest
I have a sword with angle approaching a point_direction at mouse.

What I want is, when I click the mouse I can start drag its angle and when I release the mouse, the sword swing approach the angle stored at the start (when the mouse clicked.) Then starts again.

I do drag from angle 5 to -5 but it did swing around approaching from the other way. I see mouse pointing return 355 when I do the released, and it does swing approach the 5.

So.. how could I get this 355 to -5 (so the dif is 10,) but I also want to have a 355 (so the dif is 350) if I do a long drag?

How could I get a double swing (720 dif) if I cycled the mouse around the sword 2 times?!!

And how could I aprroach it?
Or is there any other way?

Thanks in advance
 
S

Samus

Guest
You only want it to swing one way, right?

Have a Boolean variable for whether you are dragging the sword or not and a variable holding the angle of the sword, than try this in the step event:
Code:
if(abs(urSwingVariable) != 355) && (!urBooleanDragVariable) urSwingVariable += <whatever u want>;
 
N

noobhere

Guest
Sorry for the very late reply, @Samus.
Thanks. Actually I want it to swing two way. And I've done a boolean for dragging the sword and use image_angle as the variable holding the angle.
I'll share my code.. wait..
 
N

noobhere

Guest
Create Event:
Code:
drag = false;
swing = false;
angTo = 0;
angDif = 0;
Step Event:
Code:
angDif = image_angle-angTo;
if(mouse_check_button_pressed(mb_left))
{
 if(!swing)
 {
  drag = true;
  angTo = image_angle;
 }
}
if(mouse_check_button_released(mb_left))
{
 if(drag)
 {
  if(abs(angDif) > 0) swing = true;
  drag = false;
 }
}
if(swing)
{
 if(abs(angDif) > 1) image_angle -= angDif*.2;
 else swing = false;
}
else image_angle = point_direction(x,y,mouse_x,mouse_y);
Draw Event:
Code:
if(drag) for(i=5; i<=abs(angDif); i+=5;) draw_circle(x+lengthdir_x(36,angTo+i*sign(angDif)),y+lengthdir_y(36,angTo+i*sign(angDif)),1,false);
draw_self();
 
N

noobhere

Guest
I found I could get 355 to -5 by minus it 360. But when/where should I do it? Where should I put the '-360' code?
Or is there any other way?
 
N

noobhere

Guest
@Morendral Great custom script! This is what I want! Swing wherever angle I want!
Its swing can reach until 180 from its before-angle.
upload_2018-7-23_9-6-15.png
upload_2018-7-23_9-4-49.png
Now, how to get the full spin? It's seems limited to 180? Thanks in advance.
 

Morendral

Member
That script gives you the smallest difference in angle from start to finish. If you want it to do more, you'll have to figure that part out on your own. Look at how that script works and understand it. You should also think of stopping how many complete rotations it makes since I believe that was also something you wanted
 
Top