rotate around center (0,0)

miharomiharo 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

  • BonepileGamesBonepileGames Member Posts: 194
    edited April 2014

    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.

  • TosanuTosanu Member, PRO Posts: 388

    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.

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2014

    @Tosanu said:
    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.

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    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)

  • miharomiharo Member, PRO Posts: 41

    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 :)

  • miharomiharo Member, PRO Posts: 41
    edited April 2014

    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...

  • miharomiharo Member, PRO Posts: 41

    Anyone?

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2014

    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.

  • SocksSocks London, UK.Member Posts: 12,822

    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

  • SocksSocks London, UK.Member Posts: 12,822

    Another simpler way to do it:

    Link: https://www.mediafire.com/?9cxuu89523rwwgl

  • miharomiharo Member, PRO Posts: 41

    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...

  • SocksSocks London, UK.Member Posts: 12,822

    @miharo said:
    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' !!

  • miharomiharo Member, PRO Posts: 41

    yes i saw that right away...
    on second one, what is the best way to make spinning radius larger?

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2014

    @miharo said:
    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 ! :)

  • miharomiharo Member, PRO Posts: 41

    agreed.. thanks again :)

  • miharomiharo Member, PRO Posts: 41

    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...

Sign In or Register to comment.