I wonder if this (see picture) would work without using physics behavior (revolute joint).

But I do not know how to calculate the angular velocity/speed of the object if it is hit by a projectile or hits a static platform.

Thanks

5 posts
• Page **1** of **1**

I wonder if this (see picture) would work without using physics behavior (revolute joint).

But I do not know how to calculate the angular velocity/speed of the object if it is hit by a projectile or hits a static platform.

Thanks

But I do not know how to calculate the angular velocity/speed of the object if it is hit by a projectile or hits a static platform.

Thanks

You do not have the required permissions to view the files attached to this post.

**Posts:**93**Reputation:**1,466

B

15
S

3
G

3
Giganten wrote:I wonder if this (see picture) would work without using physics behavior (revolute joint).

But I do not know how to calculate the angular velocity/speed of the object if it is hit by a projectile or hits a static platform.

Thanks

Why you don't want to use physics behaviour? It's a lot easier than doing yourself the things that physics behaviour done by default.

**Posts:**421**Reputation:**6,543

B

22
S

9
G

7
Agreed it's better using the physics because it does a lot for you, but it never hurts to lean something new.

The formula that correlates velocity to angular velocity is:

displacement x velocity = angular_velocity

Where "displacement" is a vector from the pivot to the point of collision and "x" is a vector cross product. "w" will be in radians/sec so we'll need to convert it to degrees/sec by multiplying by 180/pi.

(displacement x velocity)*180/pi = angular_velocity

So to finish it up the displacement vector can be calculated with:

dispX = collisionX - pivotX

dispY = collisionY - pivotY

Also a 2d vector cross product can be defined as:

v1 x v2 = v1x*v2y - v1y*v2x

So them combining those you get a lovely formula like this:

((collisionX - pivotX)*vy - (collisionY - pivotY)*vx)*180/pi = angular_velocity

"vx" and "vy" are the x and y components of velocity. Depending on the behavior used you can also get vx and vy from speed and angle_of_motion:

vx = speed * cos(angle_of_motion)

vy = speed * sin(angle_of_motion)

So to use the formula you could make a collision event when a bullet collides with sprite, and use the bullet's position for collisionX and collisionY.

Now all we have is a way to convert linear motion to angular but it's not enough for it to look realistic. For that you'll need to use momentum and kinetic energy to calculate a collision response. There's info on it elsewhere but the formulas get kind of lengthy and really it's one of the main reasons it's much easier to use an existing physics engine.

The formula that correlates velocity to angular velocity is:

displacement x velocity = angular_velocity

Where "displacement" is a vector from the pivot to the point of collision and "x" is a vector cross product. "w" will be in radians/sec so we'll need to convert it to degrees/sec by multiplying by 180/pi.

(displacement x velocity)*180/pi = angular_velocity

So to finish it up the displacement vector can be calculated with:

dispX = collisionX - pivotX

dispY = collisionY - pivotY

Also a 2d vector cross product can be defined as:

v1 x v2 = v1x*v2y - v1y*v2x

So them combining those you get a lovely formula like this:

((collisionX - pivotX)*vy - (collisionY - pivotY)*vx)*180/pi = angular_velocity

"vx" and "vy" are the x and y components of velocity. Depending on the behavior used you can also get vx and vy from speed and angle_of_motion:

vx = speed * cos(angle_of_motion)

vy = speed * sin(angle_of_motion)

So to use the formula you could make a collision event when a bullet collides with sprite, and use the bullet's position for collisionX and collisionY.

Now all we have is a way to convert linear motion to angular but it's not enough for it to look realistic. For that you'll need to use momentum and kinetic energy to calculate a collision response. There's info on it elsewhere but the formulas get kind of lengthy and really it's one of the main reasons it's much easier to use an existing physics engine.

**Posts:**5,273**Reputation:**69,457

B

92
S

32
G

106
R0J0hound wrote:Agreed it's better using the physics because it does a lot for you, but it never hurts to lean something new...

I agree with the physics part.

but I was interested to learn how it works, and if you could apply it to the platform behavior somehow

Thanks for the formula, really interesting.

I did setup the machine (in the picture above) with physics. I have two disk setup with revolute joint one for wheel and one with revolute joint to the box above. When the box is tilted like this \ the machine moves forward but when it is tilted like this / it's slowing down. Is this behavior to be expected, and how can I get it to keep the same speed even if it is tilted like / that.

**Posts:**93**Reputation:**1,466

B

15
S

3
G

3
**Posts:**5,273**Reputation:**69,457

B

92
S

32
G

106
5 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: brunopalermo, David181 and 9 guests |