rotate around center (0,0)
miharo
Member, PRO Posts: 41
if i want to rotate object around center point as in this image, what is the best way to do this?
Comments
1) Constrain attribute (orbiting object)
constrain self.position.x to AAA * cos(self.time * BBB)+0 You can skip "+0"
2) Constrain attribute (orbiting object)
constrain self.position.y to AAA * sin(self.time * BBB)+0 You can skip "+0"
AAA - radius
BBB - speed
+0 in your case is the position where you want to orbit.
You will also need to constrain rotation to the vectorToAngle between the centerpoint and the object if you want it to always point outwards like in that image.
Or you can simply use the same speed value as the one in the constrain behaviour.
So if it is: 150 * cos(self.time * 400) + 512 . . . .
. . . then the rotation speed needs to be 400.
orbit the triangle around the center X (search for orbit threads) and constrain the angle to the inverse angle using vectorToAngle(circleX-triangleX,circleY-TriangleY)
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
thank you so much for all answers, i will work on this and let you know if i still have any issues. but i guess i got the idea
Here is a tool that might help you: http://forums.gamesalad.com/discussion/38780/free-sin-and-cos-tool-for-cool-movements-free/p1
Lump Apps and My Assets
Ok, I tried to execute information you guys gave me and I somewhat successfully make rotation BUT I have 2 issues with it. here is the link for my test project file so if anyone can help me I really appropriate it.
miharo.com/spinningtest.zip
when you run the project you press left and right keys to rotate around orbit.
problem 1
if i stop pressing key or press other key, blue line skips position. i guess i am missing something on self position constrains...
problem 2
if i press left or right, line turns 90 degree to my circle right away. clearly I made a mistake on self rotation constrain. i want it to stay vertical as it is...
Anyone?
The angle in your equation (self.time) doesn't stop when you let go of the keys, it carries on counting, so when you press the keys again it will jump to the new angle - so you need to throw some attributes and rules in there that remember when you released the key and then subtracts this from the current (still moving time) to calculate the difference between when you stopped and the current time . . . . Then when you start again you need to add this difference on to your angle.
As for the actor not being up right when moving . . . Like I said previously you don't need to use vector to angle and all that stuff, simply constrain the rotation to the same speed your actors are moving, no calculations needed - and if it is still on its side just add +90 to the value.
Here, I've just done the right key for you - hopefully you can work out the left from this example:
Link: https://www.mediafire.com/?1a29cpa92eeh20e
Another simpler way to do it:
Link: https://www.mediafire.com/?9cxuu89523rwwgl
Socks, thank you so much, you are awesome i like them both, second one kind of simpler. Either way I understand completely what was i missing...
In the second one, ignore the fact that I used 'self.Motion.Max Speed' as the attribute name, that's just one of the built in attributes, I just used it because it was free, that should really be called 'Angle', because that is what we are changing, it has nothing to do with 'Max Speed' !!
yes i saw that right away...
on second one, what is the best way to make spinning radius larger?
Change this:
Constrain self.Position.X 60</font color> * cos( self.Motion.Max Speed )+240
Constrain self.Position.Y 60</font color> * sin( self.Motion.Max Speed )+240
keep them the same unless you want ovals !
There's only three of four behaviours in the whole project, no attributes, no tables, nothing really, I'd encourage you to check stuff out and change some values, it would take you 10-20 seconds to discover how to make the radius bigger, just dive in and change stuff, it's a good way to learn !
agreed.. thanks again
and yes of course when you change the degree of the sin or cos circle gets bigger, duh... i didn't work on trigonometry for at least 15 years. i was on artwork and game design for a long time. re-discovering my math
thanks for help...