Godot Nature of Code  1.2.0
Nature of Code implemented in Godot Engine
Public Member Functions | List of all members
VerletPhysics.VerletRagdoll Class Reference

Simple verlet ragdoll. More...

Public Member Functions

 VerletRagdoll (VerletWorld world, Vector2 centerPosition, float height, float gravityScale=1, float tearSensitivityFactor=-1, float pointRadius=10f, bool drawIntermediatePoints=false, bool drawSupportLinks=false)
 Create a verlet ragdoll. More...
 

Detailed Description

Simple verlet ragdoll.

Definition at line 8 of file VerletRagdoll.cs.

Constructor & Destructor Documentation

◆ VerletRagdoll()

VerletPhysics.VerletRagdoll.VerletRagdoll ( VerletWorld  world,
Vector2  centerPosition,
float  height,
float  gravityScale = 1,
float  tearSensitivityFactor = -1,
float  pointRadius = 10f,
bool  drawIntermediatePoints = false,
bool  drawSupportLinks = false 
)
inline

Create a verlet ragdoll.

Parameters
worldVerlet world
centerPositionCenter position
heightBody height
gravityScaleGravity scale
tearSensitivityFactorDistance factor required to break links. Use '-1' to create an unbreakable ragdoll
pointRadiusPoint radius
drawIntermediatePointsDraw all ragdoll points
drawSupportLinksDraw support links

Definition at line 33 of file VerletRagdoll.cs.

34  {
35  Vector2 genPos()
36  {
37  return centerPosition + MathUtils.RandVector2(-5, 5, -5, 5);
38  }
39 
40  VerletPoint createPoint(float mass, float? radius = null, bool? visible = null)
41  {
42  var point = world.CreatePoint(genPos(), mass: mass, radius: radius ?? pointRadius, visible: visible ?? drawIntermediatePoints);
43  point.GravityScale = gravityScale;
44  return point;
45  }
46 
47  var headSize = pointRadius * 3;
48  var handSize = pointRadius * 2;
49  var footSize = pointRadius * 1.5f;
50  var headLength = height / 7.5f;
51 
52  head = createPoint(4, radius: headSize, visible: true);
53  shoulder = createPoint(26);
54  world.CreateLink(head, shoulder, restingDistance: 5 / 4 * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 1);
55 
56  elbowLeft = createPoint(2);
57  elbowRight = createPoint(2);
58  world.CreateLink(elbowLeft, shoulder, restingDistance: 3 / 2 * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 1);
59  world.CreateLink(elbowRight, shoulder, restingDistance: 3 / 2 * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 1);
60 
61  handLeft = createPoint(2, radius: handSize, visible: true);
62  handRight = createPoint(2, radius: handSize, visible: true);
63  world.CreateLink(handLeft, elbowLeft, restingDistance: 2 * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 1);
64  world.CreateLink(handRight, elbowRight, restingDistance: 2 * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 1);
65 
66  pelvis = createPoint(15);
67  world.CreateLink(pelvis, shoulder, restingDistance: 3.5f * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 0.8f);
68  world.CreateLink(pelvis, head, restingDistance: 4.75f * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 0.02f, visible: drawSupportLinks, color: Colors.LightBlue.WithAlpha(64));
69 
70  kneeLeft = createPoint(10);
71  kneeRight = createPoint(10);
72  world.CreateLink(kneeLeft, pelvis, restingDistance: 2 * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 1);
73  world.CreateLink(kneeRight, pelvis, restingDistance: 2 * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 1);
74 
75  footLeft = createPoint(20, radius: footSize, visible: true);
76  footRight = createPoint(20, radius: footSize, visible: true);
77  world.CreateLink(footLeft, kneeLeft, restingDistance: 2 * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 1);
78  world.CreateLink(footRight, kneeRight, restingDistance: 2 * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 1);
79  world.CreateLink(footLeft, shoulder, restingDistance: 7.5f * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 0.001f, visible: drawSupportLinks, color: Colors.LightBlue.WithAlpha(64));
80  world.CreateLink(footRight, shoulder, restingDistance: 7.5f * headLength, tearSensitivityFactor: tearSensitivityFactor, stiffness: 0.001f, visible: drawSupportLinks, color: Colors.LightBlue.WithAlpha(64));
81  }
Math utility functions
Definition: MathUtils.cs:7
static Vector2 RandVector2(Vector2 rangeX, Vector2 rangeY)
Return a Vector with coordinates in a random range (vector limits).
Definition: MathUtils.cs:92

The documentation for this class was generated from the following file: