How do I calculate angular velocity/speed

Get help using Construct 2

Post » Sat Aug 09, 2014 4:21 pm

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
You do not have the required permissions to view the files attached to this post.
B
15
S
3
G
3
Posts: 93
Reputation: 1,466

Post » Sat Aug 09, 2014 5:59 pm

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.
B
22
S
9
G
7
Posts: 421
Reputation: 6,543

Post » Sat Aug 09, 2014 7:30 pm

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.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Mon Aug 11, 2014 11:26 am

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.
B
15
S
3
G
3
Posts: 93
Reputation: 1,466

Post » Mon Aug 11, 2014 9:15 pm

I'd have to see a capx as I don't know from your description.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests