Open topic with navigation
In addition to the world gravity, forces are applied in a variety of ways. The following are the ways to apply forces to a node.
This is the most robust of all the following, and each of the following functions can be accomplished with some math and this function. The applyForce function takes five parameters: duration, dir, mode, pos, posMode.
This is the time which the force is applied for.
dir and mode
The dir is a vector which specifies what direction the force vector points. The mode argument is used to specify if the force is applied in world coordinates (viz.ABS_GLOBAL) or local coordinates (viz.ABS_LOCAL).
pos and posMode
These are used to specify where the force is applied. When not specifying the center of the object this will create a torque on the object. The posMode argument once allows one to differentiate between the world and local coordinates for the position of where the force is applied.
To visualize how the force is applied when changing the position, imagine a handle drawn from the objects center of mass to the point specified. The force will be applied to the end of the handle in the direction specified previously.
The following demonstrates using applyForce to accelerate a box upward for 3 seconds.
The applyTorque function works by passing in a vector which represents the magnitude of force to apply to each axis and the duration of which to apply the torque.
In the above example the torque is applied along the world's 'y' axis. Remember that Vizard uses a left handed coordinate system so use the left-hand rule to calculate which direction an object will rotate. Like before to apply the torque in the ball's coordinates call applyTorque like so: ball.applyTorque([0,1,0],0,viz.ABS_LOCAL), This example appears the same as before however this is only because the global 'y' and local 'y' are the same at this point.
This function is similar to the applyForce function however it does not take a duration argument and the force is constantly applied while the truster is enabled.
In the following pressing space will activate and deactivate the thruster.
This function allows one to set the desired velocity of an object and the physics engine will apply the necessary forces to maintain the velocity. In order to maintain a specific velocity this function will counteract other forces so this function typically shouldn't be used when other forces are acting on a node.
The spring is somewhat different from the rest of these forces. Once a spring is created, the spring object's location can be moved which then causes the node to spring to that location. Forces are automatically applied to create the spring affect.
There are two main parameters to the spring which are the linearKd and the linearKs. LinearKd represents the force applied by the spring. The higher the value the more force the spring will exert on the object. LinearKs represents the dampening of the oscillation of the spring. The higher this value the slower the object will spring to the position. These values can be set when adding the spring or later with the setLinearKd and setLinearKs functions.
In the following pressing space will cause the ball to spring to the next location specified by pos.
More than one spring can be added to an object, and in this case the object will reach an equilibrium somewhere between the springs.
In the following press left and up to apply a force and watch the springs reposition the ball in the center.
This function simulates forces of attraction between two objects. Adding attractors for all objects to all other objects in the world allows for the simulation of planetary gravity.
The function takes two parameters, the strength and the exponent. The larger the strength the larger the force will be, and the larger the exponent the quicker the force will diminish as the distance between the objects grow.
The following is an example of a binary star system where they are both orbiting around their center of mass.
Setting the strength to a negative value pushes the objects away from each other which demonstrates repulsion.
Physics Shapes - In depth discussion of the collide methods.
Forces - More detail on applyForce and applyTorque.
Joints - In depth overview of the joint types.
Motors - In depth explanation of how each motor works with each joint.
Physics Command Table
Tracking an object
Callbacks & complex shapes
Forces & materials