Free Yourselves From The Tyranny of Center Only Rotations!

13»

Comments

  • GamersRejoiceGamersRejoice Member Posts: 817
    I tried that and it worked, but only when I checked moveable and used rotate. I tried rotate to and it didn't work and interpolate seems to rotate from the wrong place. My brain... melting....
  • Rob2Rob2 Member Posts: 2,402
    @Gamers.. what are you trying to do ? :)
  • GamersRejoiceGamersRejoice Member Posts: 817
    I have an actor that interpolates back and forth from side to side. I then wanted to make it interpolate rotatation from self.positionX and Y offset. For some reason it isn't rotating from the correct position.
  • Rob2Rob2 Member Posts: 2,402
    Maybe this will help you

    image

    The cookbook explanation seems very confusing to me and sin and cos are wrong and where atan comes into it I don't know....

    If you look at that diagram you should be able to work out any variation of rotation problems.
    There is a simple orbit project at the end of here.. http://gamesalad.com/forums/topic.php?id=20867
  • Rob2Rob2 Member Posts: 2,402
    This is the equation for rotating an actor around a pivot point. Distance is just the magnitude from actor to pivot.

    actor X = pivot X + (distance * (cos (angle)))
    actor Y = pivot Y + (distance * (sin (angle)))

    If you want to do something like this



    You would need to account for any starting angle above 0 degrees and add it to angle in the formula above.

    This would normaly be achieved with a vector to angle (actorX-pivotX,actorY-pivotY)

    and a less pretty one I did :)

    http://screencast-o-matic.com/watch/cXQocI0dA
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    GamersRejoice said:
    I tried that and it worked, but only when I checked moveable and used rotate. I tried rotate to and it didn't work and interpolate seems to rotate from the wrong place. My brain... melting....

    Ok -- I just tested it with rotate, rotate to angle, rotate to position, and interpolate. All worked with moveable checked. But interestingly, interpolate also worked with moveable unchecked.

    Sorry about the brain melting! But now that its working for you -- you can just use it when needed and not think about it too much. (Besides, the GameSalad team is going to incorporate it into the rotation behaviors (soon?), so you/we won't need to have any brain melting incidents.)

    RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    GamersRejoice said:
    I tried that and it worked, but only when I checked moveable and used rotate. I tried rotate to and it didn't work and interpolate seems to rotate from the wrong place. My brain... melting....

    It should work!

    Remember that if self.offsetY is positive the pattern is:
    screenPositionX + (magnitude....
    screenPositionY - (magnitude...

    If self.offsetY is negative the pattern is:
    screenPositionX - (magnitude....
    screenPositionY + (magnitude...

    By any chance, do you have the plus and minus reversed?

    RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Rob2 said:The cookbook explanation seems very confusing to me and sin and cos are wrong and where atan comes into it I don't know....

    If you look at that diagram you should be able to work out any variation of rotation problems.
    There is a simple orbit project at the end of here.. http://gamesalad.com/forums/topic.php?id=20867

    @Rob2
    The diagram is very useful if someone knows how to use it!

    As for the thread you reference. Well.... I've also referred people to it on this forum. Its is a very clear explanation about how to get an actor to orbit. Honest, I've studied it and I do refer people to it when they need a clear explanation on how to get an object to orbit. (And the project at the end of the thread is great. I just opened it up and looked at it again.)

    But spinning an actor is not quite the same as orbiting. If you want to show others how to spin (or rotate) an actor then you will need to show the equations for that. (And not for orbiting.)

    Spinning (or rotating) an actor "off-center" requires more than the regular orbit equations. The orbiting equations only take it half way. It also requires offsetting the actor's x,y (its center) so that it gives the illusion of spinning from a different um... 'center of rotation'.

    Oh --- I just thought of something that may help clarify the difference. I think the classic orbiting equations show how to offset an actor's center of rotation in only one direction. But they do not show how to do it in both the X and Y direction. (I could be wrong about that, it just kind of popped into my head just now. It has an intuitive feel to it. And if I am wrong -- then so be it. But it might help clarify what I'm talking about.)

    Well any way... orbiting is a partial solution. But it also needs to offset the x and y positions of the actor in proportion to the new angle. If you can show how to do that with a simpler set of equations, then I -- and probably several others -- will be happy campers.

    I do hope this helps.
    RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Rob2 said:The cookbook explanation seems very confusing to me and sin and cos are wrong and where atan comes into it I don't know....
    Hey -- that's kind of harsh.

    I am sorry that the cookbood explanation confused you, but at least I tried to make an explanation. I was trying to explain it to math haters and tried to just show them what to do. They often don't want the theory, they just want to know what to do to make it work.

    There is plenty of room in the cookbook for you to explain how to do it. But when you do, please show some working equations and don't give simple generic orbit formulas that are a partial solution. Show them exactly what to do and how to do it.

    The reversed sin and cos might be confusing to you but it is the correct thing to do.

    The "atan comes into it" to offset the x and y coordinates to give the illusion of spinning in a different center of rotation. (The actor can only rotate from its center. That is the way GameSalad rotations are set up. If you want to get off-center rotations, you have to offset the x and y coordinates to give it the illusion of rotating from somewhere other than its center.)

    If you can come up with a different set of equations, you will need to do the same. It seems to me that using atan will be the quickest route. (But there are some functional equivalents in certain conditions.)

    RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    @GamersRejoice

    I hope you haven't given up yet. Now that its morning and I can look at the graphic you sent, I can see that you have the first operations (the plus and minus) reversed. Try the following:

    screenPositionX + (magnitude....
    screenPositionY - (magnitude...

    That should get things working!

    RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Rob2 said:
    This is the equation for rotating an actor around a pivot point. Distance is just the magnitude from actor to pivot.

    actor X = pivot X + (distance * (cos (angle)))
    actor Y = pivot Y + (distance * (sin (angle)))
    .
    .
    .
    This would normaly be achieved with a vector to angle (actorX-pivotX,actorY-pivotY)

    Rob2

    I haven't had a chance to test out the corrections you have made to your original formulas. But obviously they look promising since you include a couple of videos. I had seen Tshirtbooth's video in a previous thread. He mentioned that GS had a bug that didn't make it workable yet. Perhaps that's been fixed by now.

    You gave a generic formula. It would be great if you could put it into specific GameSalad behaviors.

    On first inspection, I can say that I LIKE IT. Here are the reasons why:

    1) The corrections you made to your original formulas now take into account the x and y offset that is needed. (You called them pivotX and pivotY.)

    2) The corrected equations now include the atan calculations that are needed to offset x and y. The atan function is contained within GameSalad's vectorToAngle function. (Remember that vectorToAngle is in reality GameSalad's implementation of (atan2(y,x)*180/pi). Notice that the atan2 function gives y before x)

    3) Because it uses atan2(y,x), your formulas can get rid of the reversed cos and sin functions (so that x --> cos, and y-->sin). This looks right to those who use trig to move things in a unit circle.

    4) I haven't tested this out -- but I hope that because cos and sin are now used with their respective x and y coordinates, that it will eliminate the issue of what to do with a negative y offset value. This would be great if it did! (But this will need testing.)

    5) While your new equations actually reduce mathematically to the equations that I already offered, I think they will most likely be more palatable to many GS users. They look 'easier on the eye' and will probably be implemented easier by those who just want to plug numbers into some preset equations.

    I am very hopeful for these corrections! I won't be able to test them out until much later today. But I have a very good feeling about them.

    Thanks!
    RThurman
  • dotsonj23dotsonj23 Member Posts: 316
    Rob2 said:
    This is the equation for rotating an actor around a pivot point. Distance is just the magnitude from actor to pivot.

    actor X = pivot X + (distance * (cos (angle)))
    actor Y = pivot Y + (distance * (sin (angle)))
    ....

    I just tested this. It will rotate your actor around an offset point rather than the actors x,y. But really this is just orbiting. If will not allow you to do things like joints. For example, if you are shooting for a joint at the lower left corner of a rectangle actor and say the rectangle actor is width=100, height=20, at position X=200 and Y=200. Using a Pivot X (i.e., the X offset) of 150 and a Pivot Y (i.e. the Y offset) of 190, which is the lower left corner of the rectangle actor and you plug in the distance between the offset point and the rectangle's position into the "distance" part of the formula (i.e., magnitude(150-200, 190-200), the rectangle actor does rotate around the point 150(X), 190(Y) but not from the lower left corner (i.e, what would be a joint). Instead, the rectangle actor instantly moves down 10 and then rotates around the point 150, 190 as if you stuck a pin on the left side of the rectangle half way up its height (i.e., the left middle side of the rectangle. To stop is from moving down ten, you can make the Offset Y 200, and after rotating 360 degrees it will be in the exact same position. However, its still not acting like there is a joint at the lower left corner of the rectangle.
  • Rob2Rob2 Member Posts: 2,402
    @dotsonj23 Did you account for the initial angle from pivot to actor centre ? You need to add that angle to the angle in the equation. In your case it is about 11.3 degrees I think (?) .
    Rob2 said:
    This is the equation for rotating an actor around a pivot point. Distance is just the magnitude from actor to pivot.

    actor X = pivot X + (distance * (cos (angle)))
    actor Y = pivot Y + (distance * (sin (angle)))

    You would need to account for any starting angle above 0 degrees and add it to angle in the formula above.

    This would normaly be achieved with a vector to angle (actorX-pivotX,actorY-pivotY)

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Rob2

    Your modifications to the equations work great! Thank you for showing how to do this.

    For those who may still be interested, the specific behaviors look like:

    Constrain Attribute: self.Position.X To:
    sceneX+magnitude(self.offsetX,self.offsetY)*cos(self.Rotation+vectorToAngle(self.offsetX,self.offsetY))

    Constrain Attribute: self.Position.Y To:
    sceneY+magnitude(self.offsetX,self.offsetY)*sin(self.Rotation+vectorToAngle(self.offsetX,self.offsetY))

    These equations have a number of advantages over the original ones that I proffered. (I listed those advantages in a previous post.) I would encourage everyone to use Rob2's solution.

    (I would also [again] encourage the GameSalad dev team to implement the ability to do "off-center" rotations within the three rotation behaviors.)

    I created a little demo showing the above equations. You can download it here:

    http://www.speedyshare.com/files/30344525/NewOffCenterRotation.zip

    The only change I made (in the demo) to the above equations was to change the first operation from plus to minus. This way, the positive X,Y coordinates are going to the right and up, and negative X,Y coordinates go left and down. (More in line with GameSalad's coordinate system.)

    Again, thanks for showing how to do this.

    RThurman

    p.s. I modified the cookbook explanation to reflect these equations. Hopefully it will be less "confusing".
  • lildragnlildragn Member Posts: 105
    Hi RThurman, the link on speedyshare is dead... do you have another somewhere?

    Would like to take a look at the example.

    thx

    ~t
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    lildragn said:
    Would like to take a look at the example.

    OK -- I put a demo out on GameSalad. Search for "Off-Center Rotation" or similar terms.
  • lildragnlildragn Member Posts: 105
    Cheers!
  • GSHopefulGSHopeful Member Posts: 17
    Would something like this solution help me get a windmill going? I've been trying for the last few days without any success...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    @GSHopeful
    This would be a solution only if you want your windmill to wobble off-center.

    If you want to learn to do a straight-forward actor rotation, there are several demo's in GameSalad creator. Do a search for "rotate" and you will find what you are looking for.
  • GSHopefulGSHopeful Member Posts: 17
    Thanks for the response RThurman. Unfortunately, it's not what I'm looking for. Although I still think this thread is awesome, and so are you for sharing this with the community!
Sign In or Register to comment.