Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Character.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 using SiliconStudio.Core.Mathematics;
6 
7 namespace SiliconStudio.Paradox.Physics
8 {
9  public class Character : Collider
10  {
11  /// <summary>
12  /// Initializes a new instance of the <see cref="Character"/> class.
13  /// </summary>
14  /// <param name="collider">The collider.</param>
15  internal Character(ColliderShape collider)
16  : base(collider)
17  {
18  }
19 
20  /// <summary>
21  /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
22  /// </summary>
23  public override void Dispose()
24  {
25  if (KinematicCharacter != null)
26  {
27  KinematicCharacter.Dispose();
28  KinematicCharacter = null;
29  }
30 
31  base.Dispose();
32  }
33 
34  private float fallSpeed = 55.0f; // Terminal velocity of a sky diver in m/s. (from bullet source defaults)
35  private float jumpSpeed = 10.0f; // (from bullet source defaults)
36  private Vector3 upAxis = Vector3.UnitY;
37 
38  internal BulletSharp.KinematicCharacterController KinematicCharacter;
39 
40  /// <summary>
41  /// Gets or sets the fall speed.
42  /// </summary>
43  /// <value>
44  /// The fall speed.
45  /// </value>
46  public float FallSpeed
47  {
48  get { return fallSpeed; }
49  set
50  {
51  fallSpeed = value;
52  KinematicCharacter.SetFallSpeed(fallSpeed);
53  }
54  }
55 
56  /// <summary>
57  /// Gets or sets the maximum slope.
58  /// </summary>
59  /// <value>
60  /// The maximum slope.
61  /// </value>
62  public float MaxSlope
63  {
64  get { return KinematicCharacter.MaxSlope; }
65  set { KinematicCharacter.MaxSlope = value; }
66  }
67 
68  /// <summary>
69  /// Gets or sets the jump speed.
70  /// </summary>
71  /// <value>
72  /// The jump speed.
73  /// </value>
74  public float JumpSpeed
75  {
76  get { return jumpSpeed; }
77  set
78  {
79  jumpSpeed = value;
80  KinematicCharacter.SetJumpSpeed(jumpSpeed);
81  }
82  }
83 
84  /// <summary>
85  /// Jumps this instance.
86  /// </summary>
87  public void Jump()
88  {
89  KinematicCharacter.Jump();
90  }
91 
92  /// <summary>
93  /// Gets or sets up axis.
94  /// </summary>
95  /// <value>
96  /// Up axis.
97  /// </value>
98  /// <exception cref="System.Exception">Invalid Up Axis.</exception>
99  public Vector3 UpAxis
100  {
101  get { return upAxis; }
102  set
103  {
104  if (value == Vector3.UnitX)
105  {
106  KinematicCharacter.SetUpAxis(0);
107  }
108  else if (value == Vector3.UnitY)
109  {
110  KinematicCharacter.SetUpAxis(1);
111  }
112  else if (value == Vector3.UnitZ)
113  {
114  KinematicCharacter.SetUpAxis(2);
115  }
116  else
117  {
118  throw new Exception("Invalid Up Axis.");
119  }
120 
121  upAxis = value;
122  }
123  }
124 
125  /// <summary>
126  /// Gets or sets the gravity.
127  /// </summary>
128  /// <value>
129  /// The gravity.
130  /// </value>
131  public float Gravity
132  {
133  get { return -KinematicCharacter.Gravity; }
134  set { KinematicCharacter.Gravity = -value; }
135  }
136 
137  /// <summary>
138  /// Gets a value indicating whether this instance is on the ground.
139  /// </summary>
140  /// <value>
141  /// <c>true</c> if this instance is grounded; otherwise, <c>false</c>.
142  /// </value>
143  public bool IsGrounded
144  {
145  get { return KinematicCharacter.OnGround(); }
146  }
147 
148  /// <summary>
149  /// Teleports the specified target position.
150  /// </summary>
151  /// <param name="targetPosition">The target position.</param>
152  public void Teleport(Vector3 targetPosition)
153  {
154  KinematicCharacter.Warp(targetPosition);
155  }
156 
157  /// <summary>
158  /// Moves the specified movement.
159  /// </summary>
160  /// <param name="movement">The movement.</param>
161  public void Move(Vector3 movement)
162  {
163  KinematicCharacter.SetWalkDirection(movement);
164  }
165  }
166 }
void Teleport(Vector3 targetPosition)
Teleports the specified target position.
Definition: Character.cs:152
void Jump()
Jumps this instance.
Definition: Character.cs:87
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
static readonly Vector3 UnitZ
The Z unit SiliconStudio.Core.Mathematics.Vector3 (0, 0, 1).
Definition: Vector3.cs:67
static readonly Vector3 UnitX
The X unit SiliconStudio.Core.Mathematics.Vector3 (1, 0, 0).
Definition: Vector3.cs:57
static readonly Vector3 UnitY
The Y unit SiliconStudio.Core.Mathematics.Vector3 (0, 1, 0).
Definition: Vector3.cs:62
override void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resourc...
Definition: Character.cs:23
using SiliconStudio.Paradox. Physics
void Move(Vector3 movement)
Moves the specified movement.
Definition: Character.cs:161