Rotate according to distance

Get help using Construct 2

Post » Wed Jun 05, 2013 5:05 pm

Hi to all !
Does someone knows how to do that ?
I'm looking for a formula that applies to a circle sprite. When the sprite moves horizontally, its rotates according to its size.
That could be useful for wheels of a car as the object is dragged through the screen.
Such a formula could be turned into a behavior, what do you think ?
B
28
S
12
G
5
Posts: 218
Reputation: 5,162

Post » Wed Jun 05, 2013 5:20 pm

Let's do some maths then !
Length = Pi*Sprite.width*rotation(in )/360
So if you have the distance (dt*speed), then you have the rotation :
Rotation = dt*speed*360/(Pi*Sprite.width)
B
17
S
8
G
4
Posts: 461
Reputation: 6,087

Post » Thu Jun 06, 2013 12:22 am

@Guizmus
Oh great !
Well I undersrand the math but practically, how will it look like in Construct ?
B
28
S
12
G
5
Posts: 218
Reputation: 5,162

Post » Thu Jun 06, 2013 12:57 am

https://dl.dropboxusercontent.com/u/123756210/carTires.capx
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Thu Jun 06, 2013 8:00 am

Hi @Farmerdwight
Thanks a lot !
That's exactly what I needed ! But can you explain the formula "set angle to cartire.x degrees" ? Does it take in consideration the size of the sprite ?
B
28
S
12
G
5
Posts: 218
Reputation: 5,162

Post » Thu Jun 06, 2013 9:49 am

set Angle is quite simple to understand.
When you have a sprite selected, you see handles to resize it, and also a center point, with a handle on its side, to rotate the sprite. Basic orientation is 0.
If you set another angle on the sprite, it will rotate around its center, the origin point, witch you can change in the animation editing interface (dbl click on the sprite). Be carefull, there is a different center for each frame of each animations !

How to implement the mats in C2 ? Depends how your "car" is built. If it's, let's say, 1 sprite for the body of the car, and 1 sprite per wheel, you should put those in a container.
In the event sheet, I would create a function "car.move" (with a direction and a speed maybe ? Everything depends on your implementation). In this function, I would put some action on the car wheel sprite, "set angle to dt*car.speed*360/(3.1415*Sprite.width) + wheel.angle". Of course, you would have to change car.speed, Sprite.width and wheel.angle with the right variables, depending on the name of your objects and the behavior you use to move the car (how the speed is store)
B
17
S
8
G
4
Posts: 461
Reputation: 6,087

Post » Thu Jun 06, 2013 4:52 pm

Thanks for the lesson. I appreciate
B
28
S
12
G
5
Posts: 218
Reputation: 5,162


Return to How do I....?

Who is online

Users browsing this forum: bbjGames, Dain, LaurenceBedford, lucstanislash, OddConfection and 11 guests