Rotate object around another spot- still possible?

For questions about using Classic.

Post » Wed Sep 07, 2011 8:06 am

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?sparkfeather2011-09-07 08:08:45
B
3
G
2
Posts: 58
Reputation: 1,166

Post » Wed Sep 07, 2011 9:49 am

[code]+ 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)[/code]
This is wrong. Replace it with this:

[code]+ 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 [/code]

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.tulamide2011-09-07 10:00:02
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Sep 08, 2011 11:18 am

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.sparkfeather2011-09-08 11:19:04
B
3
G
2
Posts: 58
Reputation: 1,166


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests