forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixedAngleGridDemo.cs
More file actions
70 lines (62 loc) · 2.5 KB
/
Copy pathFixedAngleGridDemo.cs
File metadata and controls
70 lines (62 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Physics;
public class FixedAngleGridScene : SceneCreationSettings {};
public class FixedAngleGridDemo : SceneCreationAuthoring<FixedAngleGridScene> {}
public class FixAngleGridDemoSystem : SceneCreationSystem<FixedAngleGridScene>
{
public override void CreateScene(FixedAngleGridScene sceneSettings)
{
BlobAssetReference<Unity.Physics.Collider> collider = Unity.Physics.BoxCollider.Create(new BoxGeometry
{
Center = float3.zero,
Orientation = quaternion.identity,
Size = new float3(0.25f),
BevelRadius = 0.0f
});
CreatedColliders.Add(collider);
quaternion orientationA = quaternion.identity;
bool identityA = true;
if (!identityA)
{
orientationA = quaternion.AxisAngle(new float3(0, 1, 0), (float)math.PI * 3.0f / 2.0f);
}
quaternion orientationB = quaternion.identity;
bool identityB = true;
if (!identityB)
{
orientationB = quaternion.AxisAngle(math.normalize(new float3(1)), (float)math.PI / 4.0f);
}
// Make some joints with fixed position, limited 3D angle
for (int i = 0; i < 10; i++)
{
// Create a body
Entity body = CreateDynamicBody(
new float3((i - 4.5f) * 1.0f, 0, 0), quaternion.identity, collider, float3.zero, float3.zero, 1.0f);
// Create the ragdoll joint
float3 pivotLocal = float3.zero;
float3 pivotInWorld = math.transform(GetBodyTransform(body), pivotLocal);
var jointData = new PhysicsJoint
{
BodyAFromJoint = new RigidTransform(orientationA, pivotLocal),
BodyBFromJoint = new RigidTransform(orientationB, pivotInWorld)
};
jointData.SetConstraints(new FixedList128<Constraint>
{
Length = 2,
[0] = Constraint.BallAndSocket(),
[1] = new Constraint
{
ConstrainedAxes = new bool3(true, true, true),
Type = ConstraintType.Angular,
Min = math.max(i - 5, 0) * 0.1f,
Max = i * 0.1f,
SpringDamping = Constraint.DefaultSpringDamping,
SpringFrequency = Constraint.DefaultSpringFrequency
}
});
CreateJoint(jointData, body, Entity.Null);
}
}
}