Jump to content


Photo

Rotating around a point help.


  • Please log in to reply
5 replies to this topic

#1 Morning_Fresh_

Morning_Fresh_

    GMC Member

  • GMC Member
  • 55 posts
  • Version:GM8

Posted 04 July 2012 - 11:24 PM

I've created a code to make a object rotate around a point, here is the code:
hubx=view_xview[0]+(view_wview[0]/2)
huby=view_yview[0]+(view_hview[0]*0.9)

angle=-5
dX = x-hubx;
dY = y-huby;
COS = cos(degtorad(angle));
SIN = -sin(degtorad(angle));
x = (dX*COS-dY*SIN+hubx)
y = (dY*COS+dX*SIN+huby)

The problem with this is that if the view moves so does the circle, and therefore it makes the distance and angle change between the point and the circle. I need to find out a way to make the circle stay always 50 pixels (variable "spoke") from the point, and make sure the angle doesn't change.

Update: I found out a way to make the object keep its distance the same using this code:
dist=point_distance(hubx,huby, x,y)
dir=point_direction(hubx,huby, x,y)

if dist<spoke or dist>spoke and dist>0
{
xx=(x-hubx)/dist
yy=(y-huby)/dist

x=hubx + xx * spoke
y=huby + yy * spoke
}
But I still cant keep the angle the same. Please help!
  • 0

#2 PoniesForPeace

PoniesForPeace

    puzzling

  • GMC Member
  • 493 posts
  • Version:GM:Studio

Posted 05 July 2012 - 01:28 AM

Can you show us a picture? Can you "football coach" it with MS paint? I don't get what you are trying to do, you want the angle to change but you want the angle to remain the same?

Edited by PoniesForPeace, 05 July 2012 - 01:29 AM.

  • 0

#3 Morning_Fresh_

Morning_Fresh_

    GMC Member

  • GMC Member
  • 55 posts
  • Version:GM8

Posted 05 July 2012 - 03:16 AM

Can you show us a picture? Can you "football coach" it with MS paint? I don't get what you are trying to do, you want the angle to change but you want the angle to remain the same?


Its even hard to "football coach" it but ill give it a try
Posted Image
Now when the view moves so does the circle, therefore changing the angle (between the point (hubx,huby) and the circle).
This is really hard to explain. So if you have better code for rotating around a moving point, don't be shy to post it.
  • 0

#4 PoniesForPeace

PoniesForPeace

    puzzling

  • GMC Member
  • 493 posts
  • Version:GM:Studio

Posted 05 July 2012 - 10:33 AM


Can you show us a picture? Can you "football coach" it with MS paint? I don't get what you are trying to do, you want the angle to change but you want the angle to remain the same?


Its even hard to "football coach" it but ill give it a try
Posted Image
Now when the view moves so does the circle, therefore changing the angle (between the point (hubx,huby) and the circle).
This is really hard to explain. So if you have better code for rotating around a moving point, don't be shy to post it.

The angle is supposed to change, how else would the point orbit?
pointX=centerX+lengthdir_x(50,angle)
pointY=centerY+lengthdir_y(50,angle)
angle+=1
  • 0

#5 Morning_Fresh_

Morning_Fresh_

    GMC Member

  • GMC Member
  • 55 posts
  • Version:GM8

Posted 05 July 2012 - 02:14 PM



Can you show us a picture? Can you "football coach" it with MS paint? I don't get what you are trying to do, you want the angle to change but you want the angle to remain the same?


Its even hard to "football coach" it but ill give it a try
Posted Image
Now when the view moves so does the circle, therefore changing the angle (between the point (hubx,huby) and the circle).
This is really hard to explain. So if you have better code for rotating around a moving point, don't be shy to post it.

The angle is supposed to change, how else would the point orbit?
pointX=centerX+lengthdir_x(50,angle)
pointY=centerY+lengthdir_y(50,angle)
angle+=1


Dont worry about it, I'm really bad at describing things and I fixed it anyways. Thanks for the help!
  • 0

#6 Dreamerxyz

Dreamerxyz

    GMC Member

  • New Member
  • 1 posts
  • Version:GM8

Posted 07 July 2012 - 07:01 AM

I've had a similar problem getting moons to orbit a planet. My solution is below

Turning object

Create Event:

set variable var_hubangle to 0
Set speed to (whatever you want)

Step Event:

set var_hubangle to point_direction(hub.x,hub.y,x,y)
set direction to var_hubangle -90

In this case the distance from the hub to the object is whatever distance is when the object is created and doesn't change.You can also use this to have objects orbiting moving objects
the only problem is that the orbiting object may fly off depending on the moving speed.The solution is to replace -90 with a variable i'll call var_turn.
Then in the step event add this

set var_distance to point_distance(hub.x,hub.y,x,y)
If var_distance is larger than (whatever you want)
set var_turn to -45
ELSE
set var_turn to -90

Replacing the negatives with positives will make it go in the other direction. positive will make it go clockwise and negative will make it go anticlockwise.

Edited by Dreamerxyz, 07 July 2012 - 09:46 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users