It looks like you're new here. If you want to get involved, click one of these buttons!

ADSentertainment
Posts: **397**Member

I've been trying to get an actor to move in an ellipse, I have been able to do it, but I want to see if I can make it so that under a certain condition, the actor will pause and stop moving. and then resume it's movement after a set amount of time. however, after doing this, the actor kinda shifts and doesn't seem to resume in a very smooth way, like it just jumps to a specific point. It might be because I don't understand the equation completely because I'm a bit new to trigonometry. Here's what I did:

Constrain Attribute: self.Position.X To 180*cos( self.Time * self.Speed %360-35)+240

Constrain Attribute: self.Position.Y To 10*sin( self.Time * self.Speed %360-35)+220

Self.Time is 100. I tried making it so that under specific conditions (I don't think they matter) self.speed will be 0 and then after 10 seconds it would change back to 100. I thought it altered the speed after playing around with the equation a bit. but I think it does something else. Could someone please explain the equation so I can see what I did wrong? Thank you!

Constrain Attribute: self.Position.X To 180*cos( self.Time * self.Speed %360-35)+240

Constrain Attribute: self.Position.Y To 10*sin( self.Time * self.Speed %360-35)+220

Self.Time is 100. I tried making it so that under specific conditions (I don't think they matter) self.speed will be 0 and then after 10 seconds it would change back to 100. I thought it altered the speed after playing around with the equation a bit. but I think it does something else. Could someone please explain the equation so I can see what I did wrong? Thank you!

Having trouble with your game? Sounds like a personal problem.

0

## Comments

372MemberFor a diagnosis, because self.time is constantly changing, when you change self.speed to 0, the expression became the sin(-35). When it became 100 again, the expression made sense again, so it jumped to the position it was supposed to.

Hope this helps!

12,821MemberI can explain the equation to you but I'm away from my computer right now, but I can do it when I get a chance later . . . .

397MemberHaving trouble with your game? Sounds like a personal problem.

12,821MemberHere's a quick demo, click and hold the mouse button anywhere in the scene to trace out an ellipse, let go of the mouse button to pause, re-pressing the mouse button continues the ellipse from where you left off:

http://www.mediafire.com/?d0d588176zyhv45

397MemberHaving trouble with your game? Sounds like a personal problem.

12,821MemberConstrain Attribute: self.Position.X To 180*cos( self.Time * self.Speed %360-35)+240180*

cos( self.Time * self.Speed %360-35)+240Cos(X) is the cosine of the angle X. If you use self.time as the angle then the angle is constantly increasing and 'cos' is constantly going from +1 to -1 to +1 (and so on) - also I never quite know why people stick %360 in here as there is no need to keep resetting the angle back to 0° when it hits 360 (maybe I'm missing something obvious).

180*cos( self.Time * self.Speed %360-35)+240The 180* part is simply multiplying this value, so +1 to -1 to +1 (and so on) . . .becomes +180 to -180 to +180 (and so on).

180*cos( self.Time *

self.Speed%360-35)+240The multiplier 'self.Speed' here will simply multiply 'self.time' (which we are using as the angle), if we just use self.time for our angle without multiplying it in some way it will count up in good old fashioned seconds (which cos will read as degrees) so it will take 6 minutes for a 360 degree complete circle as we will have to wait for 360 seconds to elapse, most people use cos and sin for circles and stuff like that and they generally want them to loop or otherwise complete in time frames much much lower than 6 minutes ! So, using self.time as your angle is too slow for most things, so we multiply self.time to make it faster.

180*cos( self.Time * self.Speed %360

-35)+240The '-35' simply adds a fixed offset to the angle cos is being used on. This has no effect on the speed of the rotation (if that's what we are doing here) it just alters our position in the rotation (or more correctly: alters the phase of cos).

180*cos( self.Time * self.Speed %360-35)

+240And the '+240' is simply adding a value onto the whole equation, so whatever number [180*cos( self.Time * self.Speed %360-35)] generates we will throw 240 onto it and your actor will be 240 pixels further to the right.

Hope some of that makes sense ! (Hope some of it is right !)

12,821MemberCool !

397MemberHaving trouble with your game? Sounds like a personal problem.

240MemberWebsite

»Twitter»Facebook»Loaded Arts - Fun for thumbs.Developer Blog

»08/01/2015 - Week 72 – Apple, the great dictator…12,821MemberCheers big ears !

: )

2Member, PROI know this was an old post but I was wondering, using Sock's method, how can I start the actor at the bottom of the screen instead of to the right? I need the actor to move in a vertical ellipse movement (portrait mode).

12,821MemberThe bottom of a circle is 270° (or -90°), so all you need to do is to add an offset.

Constrain . . .

X To Width_Of_Ellipse

`*`

cos(angle+OFFSET)+XcentreY To Height_Of_Ellipse

`*`

sin(angle+OFFSET)+YcentreSo in this case the offset would be -90° . . . .

Constrain . . .

X To Width_Of_Ellipse

`*`

cos(angle-90)+XcentreY To Height_Of_Ellipse

`*`

sin(angle-90)+Ycentre2Member, PROWorks perfectly! Thank you very much.