### Rotate Around Point (Velocity) / Maths Help

#### JeffreyDriver

• Posts: 2262
Hi,

I have a platform that rotates around a point, but my actor won't ride the platform. It's X value stays the same, though it will move up/down.

Now, I've figured out that this is because the platform doesn't have velocity. It's XY values are just updated so physics aren't working.

So my plan is to use the velocity block with some advanced mathematics to get the platform to rotate around the point, but I'm really stuck on how to achieve this as maths isn't my strong suit (I am dyslexic!)

Any ideas? Thanks.

• Posts: 2716
Do you mean this?

<a href="http://static.stencyl.com/games/37697-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/37697-0.swf</a>

« Last Edit: October 24, 2017, 03:46:59 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

#### JeffreyDriver

• Posts: 2262
Yes! That's exactly what I'm trying to do.

If I make the same platform move horizontally instead, it works fine.

But if I make it rotate instead as in the example you posted, it doesn't.

I'm working on the assumption that it's because the horizontal one has velocity and so the physics can generate friction,  whereas with the rotating one, it's just the XY values of the platform that are updating (no velocity).

See the issue below:

<a href="http://static.stencyl.com/games/37698-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/37698-0.swf</a>

« Last Edit: October 24, 2017, 04:47:49 pm by JeffreyDriver »

• Posts: 2716
I'm really stuck on how to achieve this as maths isn't my strong suit (I am dyslexic!)
A very easy way to do it without using math is installing the great Joints Extension and creating a revolute joint in each platform:
Then set the STAR actor to "Cannot be pushed" and use the "set turning speed" block to rotate it.

« Last Edit: October 24, 2017, 04:14:20 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

#### JeffreyDriver

• Posts: 2262

If anyone reading this does know the mathematics of what I'm trying to do, I'd still be interested in knowing.

• Posts: 2716
I don't know what problem you have with the Joints extension solution, but I can assure you that for this purpose, using joints is much easier, faster and reliable than using math, and you would have to use only one block instead of dozens of blocks. On the contrary, If you prefer a math solution for this case, then you are choosing the longest, most complex and problematic way. However, if you want, I can give you the project file of the same example made with mathematics instead of with Joints. In fact, I have it done too, and it works. But due to it has a certain complexity, I will not be able to explain how its mathematical formulas work.
First I did it with math, and although it works well, later I realized that doing it with Joints is much better.

« Last Edit: October 24, 2017, 05:47:32 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

#### merrak

• Posts: 2645
In theory the calculus involved could be simple (relative to other calculus topics). However, it is complicated by the fact that time in Box2D is not continuous. Rather, Box2D uses discrete time steps (set to .01 second for Stencyl). For this reason, using the motion model that Box2D already has implemented will likely be your simplest route.

One alternate approach would be to use linear splines. Compute a list of points on the edge of a circle, and then have the platform follow the path. The more points you use, the better approximation of a circle you'll have.

But any approximation introduces error, so if you're using Box2D for everything else you shouldn't introduce unnecessary error by approximating a circle. Use joints to get a proper circle.

• Posts: 2716
One alternate approach would be to use linear splines. Compute a list of points on the edge of a circle, and then have the platform follow the path. The more points you use, the better approximation of a circle you'll have.
This method, as well as any other method based in continuously setting the XY platform coordinates, will not solve the issue of this topic. The key is to use speed blocks instead, plus some mathematical formulas (applied to the speed, not to the coordinates) to force the platform to constantly and precisely follow a defined smooth circular path.

« Last Edit: October 24, 2017, 06:48:58 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

#### Justin

• Posts: 4530
I don't think merrak meant using the set x/y block to follow the path. You can set an actor's speed appropriately to follow a path of straight lines between points easily enough.

Regardless, as you've both said, joints are the better way to go if Box2D is being used anyway.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

• Posts: 2716
I don't think merrak meant using the set x/y block to follow the path. You can set an actor's speed appropriately to follow a path of straight lines between points easily enough.
Yeah, that is how I did it at first, but it was not so easy for me to set the correct magnitude of the platform speed at all times so that the movement was smooth and the player was not pushed in unwanted directions:

It works, and the result looks identical. But it can be problematic. For example, if you change the platform speed, you must change other parameters too. Otherwise, the movement may become strange and inconsistent.

So, of course, I recommend to do it with Joints.

« Last Edit: October 24, 2017, 07:00:13 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

#### merrak

• Posts: 2645
I don't think merrak meant using the set x/y block to follow the path. You can set an actor's speed appropriately to follow a path of straight lines between points easily enough.
...

This was what I meant. It would be a good alternative if you didn't have joints available.

• Posts: 2262