## Translations

Know another language? Translate this tutorial!

# Physics in Construct 2: Forces, impulses, torque and joints

Favourite 148 favourites
Tutorial written by AshleyOriginally published on 29th, September 2011 - 4 revisions

If you haven't already, check out the Physics in Construct 2: The Basics tutorial. That'll cover the basics you need to know before moving on to forces, impulses and joints.

The main fun of using Construct 2's Physics behavior is in manipulating objects. You can accelerate, hit or constrain objects using forces, impulses and joints. Here's how they work.

### What are forces, impulses and joints?

A force is "any influence that causes an object to undergo a change in speed or direction" (according to Wikipedia). Usually you apply a force to an object over a long period of time to cause it to accelerate in a direction. For example, gravity is a constant downwards force.

An impulse is like a sudden impact on an object. If a ball is hit with a bat in your game, you'd apply an impulse rather than a force, for a sudden one-off strike. The important distinction is that forces are usually applied over time, whereas an impulse is a one-off hit. Forces make objects gradually accelerate, and impulses send them speeding off right away.

Torque is a rotational force. Instead of accelerating the object towards something, torque gradually speeds up the rate of rotation.

A joint constrains the motion between two objects. In other words, it connects two objects in some way. For example, you can "hinge" two objects together. The objects are still free to rotate independently of each other - but their position is constrained, because they are joined at a point.

### How to use forces, impulses, torque and joints

The Physics behavior adds some actions to the object it was added to. You can find these in the event sheet editor mingled in with the object's ordinary actions like Set Position.

Normally you'd apply forces and torque in a continuously true condition like is left mouse button down, impulses in triggers like on collision with an object, and create joints on start of layout or after creating a new object.

## Forces

When applying a force, you can specify the strength and direction of the force, as well as the point on the object it applies.

There are three actions to apply a force. They all essentially do the same thing, but some do a bit of math behind the scenes to make it easier to specify the force you want. Apply force can apply a force on the X and Y axes separately. Apply force at angle applies a force of a particular strength at an angle (and works out the X and Y components for you). Apply force towards position applies a force of a particular strength towards a position (and works out the angle, and then the X and Y components for you).

Here's an image to demonstrate a force on The Pirate Princess:

The force (the blue arrow) can be specified in three ways: the X and Y components, the angle and strength (length of the arrow), or the strength and a position somewhere the arrow is pointing to. All three specify the same force, but each are convenient in different situations.

### Point of application

You can also supply an image point when applying a force. This allows you to apply the force from a different position on the object. By default, it's applied from the object's origin, normally in the middle of the object. Notice the blue spot where the arrow starts in the image above is in the middle of The Pirate Princess.

Suppose we want to pull The Pirate Princess by his/her hook instead of from the origin. In the image editor, an image point can be placed on the hook. Then, we can provide that image point's name or number in the force-applying action. The force is then pulled from that point. See the image below: now the force is applied from the hook.

Here's a demo project showing the difference. When you apply a force at the edge of an object, it's more likely to rotate, and move with that point in front. Forces from the middle tend to be more "floaty", as if they're orbiting.

## Impulses

The Apply Impulse actions are very similar in that you can apply an impulse with X and Y components, towards an angle, or towards a position. You can also specify the impulse point from an image point on the object. Again, applying impulses from the edge of the object are more likely to send the object off spinning.

Remember impulses are one-off hits - you probably only want to use them in triggered events like on collision with an object.

## Torque

Torque is a rotational force. Instead of giving an X and Y component, you simply enter a single value. A positive torque accelerates the object in a clockwise direction, and a negative torque accelerates the object in an anticlockwise direction.

Torque affects the object's angular velocity. That's how many degrees per second it is rotating. Again, a positive value is clockwise rotation, and negative is anticlockwise.

You can apply torque towards an angle. This applies the rotation force either clockwise or anticlockwise towards the given angle - whichever's shortest. You can also apply torque towards a position. While that might sound like an odd thing to do, it simply calculates the angle to that position, then applies the torque towards that angle.

You can't apply torque from a position. Rotation affects the whole object!

## Joints

There are two kinds of joints available to the Physics behavior.

### Revolute joint

A revolute joint is like a hinge: an object is pinned on to another object. The objects are free to rotate, but are joined together at that point. See the Physics - revolute joint example provided with Construct 2 for a demonstration. Revolute joints are created with the Create revolute joint action.

You only need to create the joint once, either on start of layout or when the objects are created or need to be attached, then it applies to the objects forever. You can join the objects from an image point, so the other object doesn't have to be attached to the origin. You don't need to apply an image point for the other object - it's attached from its current position, so make sure it's in the right place before the Create revolute joint action.

### Distance joint

A distance joint makes two objects act as if they are joined by a pole. They always stay exactly the same distance apart, although they can rotate about their attachment points. See the Physics - distance joint example provided with Construct 2 for a demonstration. Distance joints are created with the Create distance joint action.

Note the connecting pole is not shown by the action itself! If you use this action on its own, there is nothing visible joining the objects, although they act as if there was a pole joining them. The above picture and the distance joint demo use a sprite to display the pole, so it's easier to see how the joint works. You might want to do something similar in your games, since it can look odd having objects joined by an invisible pole.

You can specify image points for both objects being attached. In the action's parameters, This image point refers to a point on the object the physics behavior is added to, and That image point refers to an image point on the other object. This allows you to connect two objects by their edges, for example.

You can also specify the damping ratio and spring frequency. The spring frequency makes the connecting pole act more like a large spring. If you set it to 4 Hz and one of the objects is struck, the connection between the two objects will "bounce" a little at about 4 oscillations a second. The rate the oscillations diminish is set by the damping ratio. A damping ratio of 0 means the spring will keep oscillating forever, and 1 means the spring will stop oscillating almost immediately.

## Don't forget...

Newton's second law says "The relationship between an object's mass m, its acceleration a, and the applied force F is F = ma". In other words, if you apply a force of 100 to a small object with a low mass, you get a lot more acceleration (a) than if you applied the same force to a big object with a large mass. It should be obvious that big, heavy objects are harder to move and tend to move slower! Therefore, you may find yourself needing to use smaller forces for small objects, and larger forces for big objects. The same is true of impulses and torque.

## Conclusion

Forces, impulses and torque allow you to throw objects around in your game, setting them accelerating, rotating and flying. Joints allow you to connect objects up in fun ways. You can even make strange contraptions! Check out the Physics - vehicle example for one idea. You could try connecting a whole series of objects up by distance joints and see what happens. The possibilities are endless - and it's great fun to play with, too!

## Unlock your full gamedev potential

Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!

Plus, it's got a lot of additional features that will help you save time and make more impressive games!

### Congratulations on finishing this tutorial!

Did you learn a lot from it? Share it now with your friends!

### Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.

7
TehLulzinator 4,214 rep

This all looks great! Extensive physics features yet simple. It's a shame I won't be using any of them in my project..

Sunday, October 09, 2011 at 4:52:18 PM
4
ludodesign 30.9k rep

I loved the physics... is really usuful and fun. *-*
Is easy create some little games with it.

Tuesday, October 11, 2011 at 1:04:06 PM
3
GosuDesign 3,047 rep

Great little introduction into c2's physics. I'm off to implement some into my game.

Wednesday, December 07, 2011 at 12:45:22 AM
1
smitchell 8,609 rep

Isn't the pirate princess on this page?

Wednesday, December 14, 2011 at 11:17:21 PM
1
xeed 5,172 rep

thanks for the good description of the features.

but could you add an example for every type? i cant find out what values to enter to force an object to another.

Tuesday, January 10, 2012 at 2:05:17 PM
1
storm36969 4,443 rep

Love it, but I would love to see an example on how to make a ragdoll character out of body parts connected via hinges, and how to use it in a platformer game.. <G> I know your thinking he doesn't want much does he.. hehehe.

Tuesday, May 15, 2012 at 4:27:10 AM
1
asmag 2,786 rep

The physics behavior is fun. Thanks for this tutorial.
The physics excites you want to create increasingly sophisticated games. It is amazing how some games perfectly imitate a behavior as if it were true.

Thursday, June 14, 2012 at 11:50:41 AM
1
ZhaoYun 4,014 rep

Do we have conditions for physics?

Eg:
Force =200 | "Action"
or
Velocity = 0 | "Action"

If it was already available, I can't find it!

Tuesday, June 26, 2012 at 6:40:54 PM
1
blackmwana 2,523 rep

superb, its nice to know i can put 9 years of school physics to use :)

Wednesday, July 18, 2012 at 4:59:10 PM
1
cdpa02 3,298 rep

Thanks a lot this is exactly what i needed. i knew i needed physics but i didn't know what was what you have saved me a lot of research thank you

Tuesday, November 06, 2012 at 1:08:46 PM
1
SergioRM 6,968 rep

Thank you! Very interesting

Wednesday, November 07, 2012 at 10:52:47 PM
1
lotsst 2,258 rep

Is there a way to give a sprite a negative mass. So some elements go up in the air like a balloon? I tested it with a negative world gravity on the object, but then al my rocks also go up.

Wednesday, December 26, 2012 at 11:23:37 AM
1
brandesign 2,187 rep

Very interesting. Still I can't seem to get some thing to work. I would like to use physics for having a downward force, when on default, AND I would like to let the object go to the right. Im using force now but I want to cap the acceleration. Any ideas?!

Monday, January 07, 2013 at 9:56:05 PM
1
eltiburon 2,393 rep

very nice but im still confused i need a spring effect like sonic, when player on top of spring spring sprite change frame to lower spring, player jumps spring frame change to higher player jumps up higher.

Thursday, March 21, 2013 at 3:06:39 PM
2
storm36969 4,443 rep

We need a prismatic joint, for like spike type enemies, where there is a box for instance, and a spike attached to it, which moves up and down.. How would we accomplish this in the physics project without a prismatic joint or without motors?

Just a thought Ashley...

Friday, April 19, 2013 at 2:55:32 AM