/
Dynamics.cs
420 lines (321 loc) · 14.9 KB
/
Dynamics.cs
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Runtime.InteropServices;
using System.Collections;
using UnityEngine.Scripting;
namespace UnityEngine
{
// Use these flags to constrain motion of Rigidbodies.
public enum RigidbodyConstraints
{
// No constraints
None = 0,
// Freeze motion along the X-axis.
FreezePositionX = 0x02,
// Freeze motion along the Y-axis.
FreezePositionY = 0x04,
// Freeze motion along the Z-axis.
FreezePositionZ = 0x08,
// Freeze rotation along the X-axis.
FreezeRotationX = 0x10,
// Freeze rotation along the Y-axis.
FreezeRotationY = 0x20,
// Freeze rotation along the Z-axis.
FreezeRotationZ = 0x40,
// Freeze motion along all axes.
FreezePosition = 0x0e,
// Freeze rotation along all axes.
FreezeRotation = 0x70,
// Freeze rotation and motion along all axes.
FreezeAll = 0x7e,
}
// Option for how to apply a force using Rigidbody.AddForce.
public enum ForceMode
{
// Add a continuous force to the rigidbody, using its mass.
Force = 0,
// Add a continuous acceleration to the rigidbody, ignoring its mass.
Acceleration = 5,
// Add an instant force impulse to the rigidbody, using its mass.
Impulse = 1,
// Add an instant velocity change to the rigidbody, ignoring its mass.
VelocityChange = 2,
}
// The [[ConfigurableJoint]] attempts to attain position / velocity targets based on this flag
[Flags()]
[Obsolete("JointDriveMode is no longer supported")]
public enum JointDriveMode
{
[Obsolete("JointDriveMode.None is no longer supported")]
// Don't apply any forces to reach the target
None = 0,
[Obsolete("JointDriveMode.Position is no longer supported")]
// Try to reach the specified target position
Position = 1,
[Obsolete("JointDriveMode.Velocity is no longer supported")]
// Try to reach the specified target velocity
Velocity = 2,
[Obsolete("JointDriveMode.PositionAndvelocity is no longer supported")]
// Try to reach the specified target position and velocity
PositionAndVelocity = 3
}
// Determines how to snap physics joints back to its constrained position when it drifts off too much. Note: PositionOnly is not supported anymore!
public enum JointProjectionMode
{
// Don't snap at all
None = 0,
// Snap both position and rotation
PositionAndRotation = 1,
// Snap Position only
[Obsolete("JointProjectionMode.PositionOnly is no longer supported", true)]
PositionOnly = 2
}
[Flags]
public enum MeshColliderCookingOptions
{
None,
InflateConvexMesh = 1 << 0,
CookForFasterSimulation = 1 << 1,
EnableMeshCleaning = 1 << 2,
WeldColocatedVertices = 1 << 3
}
// WheelFrictionCurve is used by the [[WheelCollider]] to describe friction properties of the wheel tire.
public struct WheelFrictionCurve
{
private float m_ExtremumSlip;
private float m_ExtremumValue;
private float m_AsymptoteSlip;
private float m_AsymptoteValue;
private float m_Stiffness;
// Extremum point slip (default 1).
public float extremumSlip { get { return m_ExtremumSlip; } set { m_ExtremumSlip = value; } }
// Force at the extremum slip (default 20000).
public float extremumValue { get { return m_ExtremumValue; } set { m_ExtremumValue = value; } }
// Asymptote point slip (default 2).
public float asymptoteSlip { get { return m_AsymptoteSlip; } set { m_AsymptoteSlip = value; } }
// Force at the asymptote slip (default 10000).
public float asymptoteValue { get { return m_AsymptoteValue; } set { m_AsymptoteValue = value; } }
// Multiplier for the ::ref::extremumValue and ::ref::asymptoteValue values (default 1).
public float stiffness { get { return m_Stiffness; } set { m_Stiffness = value; } }
}
// The limits defined by the [[CharacterJoint]]
public struct SoftJointLimit
{
private float m_Limit;
private float m_Bounciness;
private float m_ContactDistance;
// The limit position/angle of the joint.
public float limit { get { return m_Limit; } set { m_Limit = value; } }
[Obsolete("Spring has been moved to SoftJointLimitSpring class in Unity 5", true)]
public float spring { get { return 0; } set {} }
[Obsolete("Damper has been moved to SoftJointLimitSpring class in Unity 5", true)]
public float damper { get { return 0; } set {} }
// When the joint hits the limit, it can be made to bounce off it.
public float bounciness { get { return m_Bounciness; } set { m_Bounciness = value; } }
/// Within the contact distance from the limit contacts will persist in order to avoid jitter.
public float contactDistance { get { return m_ContactDistance; } set { m_ContactDistance = value; } }
[Obsolete("Use SoftJointLimit.bounciness instead", true)]
public float bouncyness { get { return m_Bounciness; } set { m_Bounciness = value; } }
}
public struct SoftJointLimitSpring
{
private float m_Spring;
private float m_Damper;
// If greater than zero, the limit is soft. The spring will pull the joint back.
public float spring { get { return m_Spring; } set { m_Spring = value; } }
// If spring is greater than zero, the limit is soft.
public float damper { get { return m_Damper; } set { m_Damper = value; } }
}
// How the joint's movement will behave along its local X axis
public struct JointDrive
{
private float m_PositionSpring;
private float m_PositionDamper;
private float m_MaximumForce;
[Obsolete("JointDriveMode is obsolete")]
// Whether the drive should attempt to reach position, velocity, both or nothing
public JointDriveMode mode { get { return (JointDriveMode)0; } set {} }
// Strength of a rubber-band pull toward the defined direction. Only used if /mode/ includes Position.
public float positionSpring { get { return m_PositionSpring; } set { m_PositionSpring = value; } }
// Resistance strength against the Position Spring. Only used if /mode/ includes Position.
public float positionDamper { get { return m_PositionDamper; } set { m_PositionDamper = value; } }
// Amount of force applied to push the object toward the defined direction.
public float maximumForce { get { return m_MaximumForce; } set { m_MaximumForce = value; } }
}
public enum RigidbodyInterpolation
{
// No Interpolation.
None = 0,
// Interpolation will always lag a little bit behind but can be smoother than extrapolation.
Interpolate = 1,
// Extrapolation will predict the position of the rigidbody based on the current velocity.
Extrapolate = 2
}
// The JointMotor is used to motorize a joint.
public struct JointMotor
{
private float m_TargetVelocity;
private float m_Force;
private int m_FreeSpin;
// The motor will apply a force up to /force/ to achieve /targetVelocity/.
public float targetVelocity { get { return m_TargetVelocity; } set { m_TargetVelocity = value; } }
// The motor will apply a force.
public float force { get { return m_Force; } set { m_Force = value; } }
// If /freeSpin/ is enabled the motor will only accelerate but never slow down.
public bool freeSpin { get { return m_FreeSpin == 1; } set { m_FreeSpin = value ? 1 : 0; } }
}
// JointSpring is used add a spring force to [[HingeJoint]] and [[PhysicMaterial]].
public struct JointSpring
{
// The spring forces used to reach the target position
public float spring;
// The damper force uses to dampen the spring
public float damper;
// The target position the joint attempts to reach.
public float targetPosition;
// We have to keep those as public variables because of a bug in the C# raycast sample.
}
// JointLimits is used by the [[HingeJoint]] to limit the joints angle.
public struct JointLimits
{
private float m_Min;
private float m_Max;
private float m_Bounciness;
private float m_BounceMinVelocity;
private float m_ContactDistance;
public float min { get { return m_Min; } set { m_Min = value; } }
public float max { get { return m_Max; } set { m_Max = value; } }
public float bounciness { get { return m_Bounciness; } set { m_Bounciness = value; } }
public float bounceMinVelocity { get { return m_BounceMinVelocity; } set { m_BounceMinVelocity = value; } }
public float contactDistance { get { return m_ContactDistance; } set { m_ContactDistance = value; } }
[Obsolete("minBounce and maxBounce are replaced by a single JointLimits.bounciness for both limit ends.", true)]
public float minBounce;
[Obsolete("minBounce and maxBounce are replaced by a single JointLimits.bounciness for both limit ends.", true)]
public float maxBounce;
}
// ControllerColliderHit is used by CharacterController.OnControllerColliderHit to give detailed information about the collision and how to deal with it.
[StructLayout(LayoutKind.Sequential)]
[RequiredByNativeCode]
public partial class ControllerColliderHit
{
internal CharacterController m_Controller;
internal Collider m_Collider;
internal Vector3 m_Point;
internal Vector3 m_Normal;
internal Vector3 m_MoveDirection;
internal float m_MoveLength;
internal int m_Push;
// The controller that hit the collider
public CharacterController controller { get { return m_Controller; } }
// The collider that was hit by the controller
public Collider collider { get { return m_Collider; } }
// The rigidbody that was hit by the controller.
public Rigidbody rigidbody { get { return m_Collider.attachedRigidbody; } }
// The game object that was hit by the controller.
public GameObject gameObject { get { return m_Collider.gameObject; } }
// The transform that was hit by the controller.
public Transform transform { get { return m_Collider.transform; } }
// The impact point in world space.
public Vector3 point { get { return m_Point; } }
// The normal of the surface we collided with in world space.
public Vector3 normal { get { return m_Normal; } }
// Approximately the direction from the center of the capsule to the point we touch.
public Vector3 moveDirection { get { return m_MoveDirection; } }
// How far the character has travelled until it hit the collider.
public float moveLength { get { return m_MoveLength; } }
//*undocumented NOT IMPLEMENTED
private bool push { get { return m_Push != 0; } set { m_Push = value ? 1 : 0; } }
}
// Describes how physic materials of colliding objects are combined.
public enum PhysicMaterialCombine
{
// Averages the friction/bounce of the two colliding materials.
Average = 0,
// Uses the smaller friction/bounce of the two colliding materials.
Minimum = 2,
// Multiplies the friction/bounce of the two colliding materials.
Multiply = 1,
// Uses the larger friction/bounce of the two colliding materials.
Maximum = 3
}
// Describes collision.
[StructLayout(LayoutKind.Sequential)]
[RequiredByNativeCode]
public class Collision
{
internal Vector3 m_Impulse;
internal Vector3 m_RelativeVelocity;
internal Rigidbody m_Rigidbody;
internal Collider m_Collider;
internal ContactPoint[] m_Contacts;
// The relative linear velocity of the two colliding objects (RO).
public Vector3 relativeVelocity { get { return m_RelativeVelocity; } }
// The [[Rigidbody]] we hit (RO). This is /null/ if the object we hit is a collider with no rigidbody attached.
public Rigidbody rigidbody { get { return m_Rigidbody; } }
// The [[Collider]] we hit (RO).
public Collider collider { get { return m_Collider; } }
// The [[Transform]] of the object we hit (RO).
public Transform transform { get { return rigidbody != null ? rigidbody.transform : collider.transform; } }
// The [[GameObject]] whose collider we are colliding with. (RO).
public GameObject gameObject { get { return m_Rigidbody != null ? m_Rigidbody.gameObject : m_Collider.gameObject; } }
// The contact points generated by the physics engine.
public ContactPoint[] contacts { get { return m_Contacts; } }
//*undocumented*
public virtual IEnumerator GetEnumerator()
{
return contacts.GetEnumerator();
}
public Vector3 impulse { get { return m_Impulse; }}
//*undocumented* DEPRECATED
[Obsolete("Use Collision.relativeVelocity instead.", false)]
public Vector3 impactForceSum { get { return relativeVelocity; } }
//*undocumented* DEPRECATED
[Obsolete("Will always return zero.", false)]
public Vector3 frictionForceSum { get { return Vector3.zero; } }
[Obsolete("Please use Collision.rigidbody, Collision.transform or Collision.collider instead", false)]
public Component other { get { return m_Rigidbody != null ? (Component)m_Rigidbody : (Component)m_Collider; } }
}
// CollisionFlags is a bitmask returned by CharacterController.Move.
public enum CollisionFlags
{
// CollisionFlags is a bitmask returned by CharacterController.Move.
None = 0,
// CollisionFlags is a bitmask returned by CharacterController.Move.
Sides = 1,
// CollisionFlags is a bitmask returned by CharacterController.Move.
Above = 2,
// CollisionFlags is a bitmask returned by CharacterController.Move.
Below = 4,
//*undocumented
CollidedSides = 1,
//*undocumented
CollidedAbove = 2,
//*undocumented
CollidedBelow = 4
}
public enum QueryTriggerInteraction
{
UseGlobal = 0,
Ignore = 1,
Collide = 2
}
public enum CollisionDetectionMode
{
Discrete = 0,
Continuous = 1,
ContinuousDynamic = 2
}
public enum ConfigurableJointMotion
{
Locked = 0,
Limited = 1,
Free = 2
}
public enum RotationDriveMode
{
XYAndZ = 0,
Slerp = 1
}
} // namespace