Constraints

Previously in the Hangman on a rope recipe, we've looked at ropes and how they can bend and move with the object(s) they are bound to. In this recipe, we will look at constraints, which are a much cheaper hinge that can be used on two objects. Specifically, we will hang a primitive pyramid object from a solid and allow it to swing on all axes.

Getting ready

  • Open My_Level.cry within the Sandbox
  • Place down a 1x1x1 meter solid and suspend it in the air roughly four meters off the ground
  • Place down a BasicEntity and change the model to objects/default/primitive_pyramid.cgf
  • Set the mass of the BasicEntity to 100

How to do it...

Begin by placing down a constraint:

  1. In the RollupBar, click on the Entities button.
  2. Under the Physics section, select Constraint.
  3. Place the constraint on the bottom surface of the solid box.
  4. Move the pyramid underneath the solid box and have the tip intersect with the radius of the constraint.
  5. The next time the player jumps into the game and pushes the pyramid, it will move according to the constraint provided.
    How to do it...

How it works...

A constraint entity can create a physical constraint between two objects. The objects will be selected automatically during the first update, by sampling the environment in a sphere around the constraint object's world position with a specified radius. The first object (the one that will own the constraint information internally) is the lightest among the found objects, and the second is the second lightest (static objects are assumed to have infinite mass, so a static object is always heavier than a rigid body).

Constraints operate in a special constraint frame. It can be set to be either the frame of the first constraint object (if UseEntityFrame is checked), or the frame of the constraint entity itself. In that frame, the constraint can operate either as a hinge around the x axis, or as a ball-in-a-socket around the y and z axes (that is, with the x axis as the socket's normal). If x limits are set to a valid range (max>min) and the yz limits are identical (such as both ends are 0), it is the former and if the yz limits are set and not x limits, it's the latter. If all limits are identical (remains 0, for instance), the constraint operates in three degrees of freedom mode (that is, it doesn't constrain any rotational axes). If all limits are set, no axes are locked initially, but there are rotational limits for them.

There's more...

Here are the definitions of the properties on the constraints.

Constraint properties

The following are the constraint properties:

  • Damping: This sets the strength of the damping on an object's movement. Most objects can work with 0 damping; if an object has trouble coming to rest, try values such as 0.2-0.3. Values of 0.5 and higher appear visually as overdamping. Note that when several objects are in contact, the highest damping is used for the entire group.
  • max_bend_torque: This is the maximum bending torque (currently it's only checked against for hinge constraints that have reached one of the X limits).
  • max_pull_force: This specifies the maximum stretching force the constraint can withstand.
  • NoSelfCollisions: This disables collision checks between the constrained objects (to be used if the constraint is enough to prevent inter-penetrations).
  • Radius: This defines spherical area to search for attachable objects.
  • UseEntityFrame: This defines whether to use the first found object or the constraint itself as a constraint frame.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.240.252