Game Development Community

Gravity

by Andre Mercier · in Torque 2D Beginner · 09/11/2013 (1:53 pm) · 2 replies

Hello, me and my friend need help on how to used gravity for PlayerObjects. Thanks.

#1
09/11/2013 (3:13 pm)
You can change gravity either using a method or directly altering its field in the Scene:

%scene = new Scene();

// Update gravity using the method.
%scene.setGravity( 0, -9.8 );

// Update gravity using the field.
%scene.Gravity = "0 -9.8";

When you set the gravity you set it through the x/y axis. Each axis is specified in metres/sec therefore setting -9.8m/s (Y Axis) gives an approximate earth gravity. Gravity affects all "dynamic" bodies in the world.
#2
09/11/2013 (11:49 pm)
Moreover, you can set how scene gravity affects your objects using:
%obj.GravityScale = 1;

// or
%obj.setGravityScale(1);

// if you want your object to stop being affected by gravity
%obj.GravityScale = 0;
When you set the gravity scale of an object its gravity equals scale*scene gravity.