Rigidbody: Joints. - Gr8-Tools/game-developer-roadmap-doc GitHub Wiki
Total time: 13 hours
- Rigidbody: A component that allows an object to be affected by physics forces like gravity and collisions.
- Joint: In Unity, a joint is a type of connection or constraint between two rigidbodies, allowing them to interact in specific ways.
- Hinge Joint: A joint that constrains the motion of connected bodies to rotate around a single axis.
- Fixed Joint: A joint that restricts all motion between connected bodies, making them act as a single rigid body.
- Spring Joint: A joint that simulates spring-like behavior between connected bodies to create elastic connections.
- Configurable Joint: A versatile joint allowing for various types of constraints and motion limitations.
- Distance Joint: A joint that maintains a specific distance between connected bodies.
-
Hinge Joint Usage:
- Usage: Hinge joints are commonly used for creating swinging or rotating objects like doors, pendulums, or gates.
-
Parameters that can be changed:
-
Limits
: Defines the range of motion for the joint. -
Use Motor
: Enables or disables the motor of the joint.
-
-
Effects of changing parameters:
- Adjusting the
Limits
parameter will limit the angle through which the joint can rotate. - Enabling the
Motor
will apply a rotational force to the connected bodies, causing them to rotate around the hinge.
- Adjusting the
- Code Implementation (C#):
HingeJoint doorHinge = gameObject.AddComponent<HingeJoint>(); doorHinge.axis = new Vector3(0, 1, 0); doorHinge.useLimits = true; // Add more properties as required for specific usage
-
Fixed Joint Usage:
- Detailed Usage: Fixed joints are useful for creating objects that need to move together, such as a physics-based vehicle or a rigid platform with multiple pieces.
-
Parameters that can be changed:
-
Enable Collision
: Determines whether the connected bodies can collide with each other. -
Break Force
: Defines the force at which the joint will break.
-
-
Effects of changing parameters:
- Changing the
Enable Collision
parameter will allow or prevent the connected bodies from colliding with each other. - Modifying the
Break Force
will determine the force at which the joint breaks and the bodies become separated.
- Changing the
- Code Implementation (C#):
FixedJoint vehicleJoint = gameObject.AddComponent<FixedJoint>(); vehicleJoint.connectedBody = otherRigidbody; // Add more properties as required for specific usage
-
Spring Joint Usage:
- Detailed Usage: Spring joints are ideal for creating connected objects with elastic behavior, such as bungee cords or shock absorbers.
-
Parameters that can be changed:
-
Spring
: Controls the spring force between the bodies. -
Damper
: Adjusts the damping of the spring force.
-
-
Effects of changing parameters:
- Adjusting the
Spring
parameter will change the force that the spring applies to bring the bodies together or push them apart. - Modifying the
Damper
parameter will impact the damping of the spring's oscillation, affecting the smoothness of the joint movement.
- Adjusting the
- Code Implementation (C#):
SpringJoint bungeeCord = gameObject.AddComponent<SpringJoint>(); bungeeCord.spring = 5000; bungeeCord.damper = 50; // Add more properties as required for specific usage
Time: 1.5 hours
Tine: 0.5 hours
By following the structured material above, students will gain a comprehensive understanding of Rigidbody Joints, empowering them to utilize these tools effectively in game development.
- Change the behaviour of traps. It will continue to detect the hero by SphereCast, but we will change the catch process. When the hero is detected, it should be "chained" to the trap, reducing the distance to the trap. I suggest you use SpringJoin to imitate it. With help of SpringJoint you could provide the possibility to twitch around the trap, but only around. Break the joint after time end.
Time: 2 hours
- Change the behaviour of target once again. We will imitate the behaviour of "punching bag": every time you hit this bag it will twitch around a virtual center point, trying to return to it (here the example of behaviour). There is the process of hitting:
- Hero casts a raycast of fixed distance (not huge)
- If cast collides the target, it should produce the hit force at the position of hit that should be applied to target in the direction of raycast.
- The module of force depends on the distance to aim: the closer the object then greater the force.
Time: 2 hours
- Reconfigure the space of game. Upscale the plane (floor) at least twice and set up
wall
layer. Now touching the floor will result in a loss. Above the floor there are elevations that look like islands in the ocean. These elevations must be connected by "platforms", which are a chain of objects connected by Joints. Thus, a path is formed from one end of the location to the other.
The hero should be spawned at one end of this path and the target on the other one. The hero should reduce the distance to the target to hit it as there is the upper bound of hit distance.
Suggest you to create some empty objects that will imitate spawn points. You can place these objects in a way, you want. Create script that will store the references to these objects and when hero should be spawned it will select one of these points (it's position) and spawn the hero at this position.
But it's not so easy as it seems. On the way there are at least 3 pendulums, which have enormous kinetic energy. Such energy that when they collide with the hero, they push him off the bridge. Use HingeJoint to simulate the pendulums.
Time: 7 hours.