Rotate object around another spot- still possible?

This forum is currently in read-only mode.
From the Asset Store
Simple resize and rotate events for any sprite, quick and easy event sheet that you can use for your own projects.
  • I want to be able to rotate my object around a certain point,

    however it doesn't seem to be functional, as in an actual

    program error?

    To explain myself I need to start from the start of my search for a solution-

    While looking for solutions, I started with finding this topic-

    http://www.scirra.com/forum/plugin-ik-solver-2_topic37671.html

    I opened this, but it wasn't quite what I was looking for, however

    I was still using the scene for experimentation.

    I then found-

    http://www.scirra.com/forum/rotate-around-point_topic37367.html

    And I used this on one of the objects in the IK solvers example scene.

    Not wanting to loose what I had, I saved, and it gave the message

    about being from an earlier version and am I sure I wish to save

    as I won't be able to use it in an earlier version, I said yes.

    The solution above I liked, so I tried to use it in my project scene,

    it wasn't working. it spins madly as if it's out of control when

    rotating, instead of the original experimental scene.

    I tried to also use this solution-

    http://www.scirra.com/tutorials/44/using-a-pivot-point-for-rotating-objects

    And that didn't work either.

    Now, I have created a new project, with the same object name and

    variables as the original scene and copy-pasted the code over,

    and that still span wildly.

    I then created a new object in the original experimental scene,

    applied the same code, and found it does the same thing.

    If you slow it down by using 'every 1000 miliseconds' you can

    see that it seems to rotate by 45 degrees, while in the new

    scene I created and tested it, it rotates by 90 degrees (an extra detail,

    the scene where it rotates 90 degrees, the distance between the

    objects location and the rotation point is about half).

    Here's a .cap of the experimental scene with the old object working,

    and the newly created object not functioning the same way.

    (use left click for functional object, right click for non-functional)

    http://ifile.it/634isr5/rotationdemo.cap

    Basically my question is.....

    What are we meant to use, if this isn't functional?

    Is it still possible at all?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • + MouseKeyboard: Right mouse button is down
    -> System: Set global variable 'angle' to angle(bone1.X, bone1.Y, bone1.ImagePointX("point"), bone1.ImagePointY("point"))
    -> System: Set global variable 'distance' to distance(bone1.X, bone1.Y, bone1.ImagePointX("point"), bone1.ImagePointY("point"))
    -> bone1: Set position to bone1.ImagePointX("point") - cos(global('angle') + 1) * global('distance'), bone1.ImagePointY("point") - sin(global('angle') + 1) * global('distance')
    -> bone1: Set angle to (angle(bone1.X, bone1.Y, bone1.ImagePointX("point"), bone1.ImagePointY("point")) + 1)

    This is wrong. Replace it with this:

    + MouseKeyboard: Right mouse button is down
    -> System: Set global variable 'angle' to angle(bone1.ImagePointX("point"), bone1.ImagePointY("point"), bone1.X, bone1.Y)
    -> System: Set global variable 'distance' to distance(bone1.X, bone1.Y, bone1.ImagePointX("point"), bone1.ImagePointY("point"))
    -> bone1: Set position to bone1.ImagePointX("point") + cos(global('angle') + 1) * global('distance'), bone1.ImagePointY("point") + sin(global('angle') + 1) * global('distance')
    -> bone1: Set angle to.angle + 1 

    Explanation: To rotate a point p2 around another point p1, you use

    p2.X = p1.X + cos(angle) * radius

    p2.Y = p1.Y + sin(angle) * radius

    You get the angle for the rotation by using the angle expression starting with the point, where you want to rotate around (in this case the image point), and ending with the point that will be rotated (in this case the hotspot)

    angle(bone1.ImagePointX("point"), bone1.ImagePointY("point"), bone1.X, bone1.Y)

    Now we need to raise or lower the angle value (to actually rotate either clockwise or counter-clockwise). The value you use, will be needed to set the angle of the object, too. In this case, it is +1, but if you'd prefer a timebased rotation, it could well be something like 90*TimeDelta, then you'd do .angle + 90 * TimeDelta as well.

    Now you need to set the angle of the object relative to the rotation. In this case, the rotation was by 1, so you add 1 to the current angle.

  • Thanks alot!, I never expected the code to be wrong cause I didn't see it different elsewhere and it worked perfectly on the original (though I did use '-' instead of '+' for the set x/y cos/sin area because for some reason the '+' didn't work but '-' did).

    After fiddling with it for awhile I did get it working with that code

    with the new objects, thank you so much!! I really needed this.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)