Circular movement
BlitzMax Forums/BlitzMax Beginners Area/Circular movement
| ||
Hi all, I know this should be basic but i just cant seem to get it right, i want an object moving around another one at a fixed distance from the center point at a constant velocity, it is in 2d, i've got it moving in arcs, ovals etc, but never in a circle :-) ![]() i was simply using: x=x+cos((pi/180)+angle)*radius y=y+sin((pi/180)+angle)*radius many thanks |
| ||
A very simple piece of code here -Graphics 640,480,32,60,0 HideMouse While Not KeyHit(key_escape) DrawText("+",MouseX(),MouseY()) DrawText("o",MouseX()+Cos(n)*50,MouseY()+Sin(n)*50) n:+1 Flip Cls Wend End If you want the orbit bigger/smaller, then change the 50 ((n)*50) value. If you want the "o" to go in the opposite direction, then use n:-1. If you want orbit to be faster, then increase the (n:+/-) value. Hope that helps :) |
| ||
thanks alot, shall check this out when at PC in afew hours, thanks for fast reply |
| ||
x=x+cos((pi/180)+angle)*radius y=y+sin((pi/180)+angle)*radius Here you shouldn't be ADDING the calculation to X and Y, you are not calculating a position relative to the last position, you are calculating a whole new position relative to a center point. x=CenterX+(Radius*(Cos(Angle))) Y=CenterY+(Radius*(Sin(Angle))) |
| ||
Gavin, How is it that you don't get a circular motion from your equation. I tryed it out and it works fine. here: SetHandle(10,10) Graphics 800,600 Local angle# = 0.0 Local radius# = 100.0 Repeat 'Cls() x# = MouseX() y# = MouseY() angle = (angle+0.5) Mod 360.0 x1=x+Cos((Pi/180.0)+angle)*radius y1=y+Sin((Pi/180.0)+angle)*radius DrawOval x1,y1,5,5 Flip(0) Until KeyDown(key_escape) although there is no need for the (pi/180.0) blitzmax sin and cos functions are set for degrees not radians. the only reason I think you would get an oval is if you have a wide screen. setting it at 640,480 would give a distorted image. if that is the case you would have to compensate by using a different radius for each x and y. |
| ||
Hi, Thanks to all, i was running in window mode, 640,480 but i get an oval movement rather than circular, tis very wierd indeed, unfortunatly i am still at work at the moment so cant test till i get home. I am most certain it is something i have done, as always :) |
| ||
What is the aspect ratio of your screen resolution? |
| ||
its a 4:3 ratio, sorted it anyway, turns out i had forgot to set 1 variable :-) thanks for eveyone's help, much appreciated |