本文整理汇总了C#中Duality.Components.Physics.RigidBody类的典型用法代码示例。如果您正苦于以下问题:C# RigidBody类的具体用法?C# RigidBody怎么用?C# RigidBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RigidBody类属于Duality.Components.Physics命名空间,在下文中一共展示了RigidBody类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1:
void ICmpUpdatable.OnUpdate()
{
float lastDelta = Time.MsPFMult * Time.TimeMult / 1000;
if (this.rigidBody == null) this.rigidBody = this.GameObj.GetComponent<RigidBody>();
if (!this.isDead)
{
if (DualityApp.Keyboard.KeyHit(Key.Space))
{
this.rigidBody.ApplyLocalImpulse(-Vector2.UnitY * this.impulseStrength);
flapTime = (Time.MsPFMult / 1000 * 3);
}
}
if(flapTime > 0)
{
FrontWing.GameObj.Transform.Angle = -MathF.PiOver4;
BackWing.GameObj.Transform.Angle = MathF.PiOver4;
flapTime -= lastDelta;
}
if(flapTime < 0)
{
FrontWing.GameObj.Transform.Angle = 0;
BackWing.GameObj.Transform.Angle = 0;
flapTime = 0;
}
if (DualityApp.Keyboard.KeyHit(Key.Escape))
{
Scene.SwitchTo(this.menuScene);
}
}
示例2: SetUp
public void SetUp()
{
var gameObject = new GameObject();
_rigidBody = new RigidBody();
gameObject.AddComponent(_rigidBody);
gameObject.AddComponent(new Transform());
}
示例3: When_copied_Then_sensor_value_is_copied
public void When_copied_Then_sensor_value_is_copied()
{
_rigidBody.IsSensor = true;
var clone = new RigidBody();
_rigidBody.CopyTo(clone);
Assert.IsTrue(clone.IsSensor);
}
示例4: OnInit
public void OnInit(InitContext context)
{
body = (RigidBody)GameObj.GetComponent(typeof(RigidBody));
jumpsRemaining = NumberOfJumps;
direction = 0;
jumpNextFrame = false;
Scriptable scriptable = (Scriptable)GameObj.GetComponent(typeof(Scriptable));
if(scriptable != null)
{
PlayerApi player = new PlayerApi(scriptable.engine, this);
scriptable.AddObject("Player", player);
scriptable.Evaluate("A_Down = function() { Player.MoveLeft() };" +
"D_Down = function() { Player.MoveRight() };" +
"D_Up = function() { Player.Stop() };" +
"A_Up = function() { Player.Stop() };" +
"Space_Down = function() { Player.Jump() };");
}
}
示例5: PickShape
private ShapeInfo PickShape(RigidBody body, Vector2 worldCoord)
{
// Special case for LoopShapes, because they are by definition unpickable
foreach (LoopShapeInfo loop in body.Shapes.OfType<LoopShapeInfo>())
{
for (int i = 0; i < loop.Vertices.Length; i++)
{
Vector2 worldV1 = body.GameObj.Transform.GetWorldPoint(loop.Vertices[i]);
Vector2 worldV2 = body.GameObj.Transform.GetWorldPoint(loop.Vertices[(i + 1) % loop.Vertices.Length]);
float dist = MathF.PointLineDistance(worldCoord.X, worldCoord.Y, worldV1.X, worldV1.Y, worldV2.X, worldV2.Y);
if (dist < 5.0f) return loop;
}
}
// Do a physical picking operation
return body.PickShape(worldCoord);
}
示例6: OnEnterState
protected internal override void OnEnterState()
{
base.OnEnterState();
// Init GUI
this.View.SuspendLayout();
this.toolstrip = new ToolStrip();
this.toolstrip.SuspendLayout();
this.toolstrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.toolstrip.Name = "toolstrip";
this.toolstrip.Text = "Collider Editor Tools";
this.toolCreateCircle = new ToolStripButton("Create Circle Shape (C)", Properties.CamViewResCache.IconCmpCircleCollider, this.toolCreateCircle_Clicked);
this.toolCreateCircle.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolCreateCircle.AutoToolTip = true;
this.toolstrip.Items.Add(this.toolCreateCircle);
this.toolCreatePoly = new ToolStripButton("Create Polygon Shape (P)", Properties.CamViewResCache.IconCmpRectCollider, this.toolCreatePoly_Clicked);
this.toolCreatePoly.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolCreatePoly.AutoToolTip = true;
this.toolstrip.Items.Add(this.toolCreatePoly);
this.toolCreateLoop = new ToolStripButton("Create Loop Shape (L)", Properties.CamViewResCache.IconCmpLoopCollider, this.toolCreateLoop_Clicked);
this.toolCreateLoop.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolCreateLoop.AutoToolTip = true;
this.toolstrip.Items.Add(this.toolCreateLoop);
this.toolstrip.Renderer = new Duality.Editor.Controls.ToolStrip.DualitorToolStripProfessionalRenderer();
this.toolstrip.BackColor = Color.FromArgb(212, 212, 212);
this.View.Controls.Add(this.toolstrip);
this.View.Controls.SetChildIndex(this.toolstrip, this.View.Controls.IndexOf(this.View.ToolbarCamera));
this.toolstrip.ResumeLayout(true);
this.View.ResumeLayout(true);
// Register events
DualityEditorApp.SelectionChanged += this.EditorForm_SelectionChanged;
DualityEditorApp.ObjectPropertyChanged += this.EditorForm_ObjectPropertyChanged;
// Initial update
this.selectedBody = this.QuerySelectedCollider();
this.InvalidateSelectionStats();
this.UpdateToolbar();
this.View.ActivateLayer(typeof(CamViewLayers.RigidBodyShapeCamViewLayer));
this.View.LockLayer(typeof(CamViewLayers.RigidBodyShapeCamViewLayer));
}
示例7: DrawWorldLooseConstraint
private void DrawWorldLooseConstraint(Canvas canvas, RigidBody bodyA, Vector2 anchorA, Vector2 anchorB)
{
Vector3 bodyPosA = bodyA.GameObj.Transform.Pos;
ColorRgba clr = this.JointColor;
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
canvas.DrawDashLine(
anchorA.X,
anchorA.Y,
bodyPosA.Z,
anchorB.X,
anchorB.Y,
bodyPosA.Z);
}
示例8: DrawWorldAxisMotor
private void DrawWorldAxisMotor(Canvas canvas, RigidBody body, Vector2 worldAxis, Vector2 localAnchor, Vector2 worldAnchor, float speed, float maxForce, float offset)
{
Vector3 bodyPos = body.GameObj.Transform.Pos;
ColorRgba clr = this.MotorColor;
Vector2 anchorToWorld = body.GameObj.Transform.GetWorldVector(localAnchor);
float axisAngle = worldAxis.Angle;
float maxForceTemp = MathF.Sign(speed) * maxForce * 0.1f;
Vector2 arrowBegin = bodyPos.Xy + worldAxis.PerpendicularRight * offset;
Vector2 arrowBase = arrowBegin + worldAxis * speed * 10.0f;
Vector2 arrowA = Vector2.FromAngleLength(axisAngle + MathF.RadAngle45 + MathF.RadAngle180, MathF.Sign(speed) * MathF.Max(offset * 0.05f, 5.0f));
Vector2 arrowB = Vector2.FromAngleLength(axisAngle - MathF.RadAngle45 + MathF.RadAngle180, MathF.Sign(speed) * MathF.Max(offset * 0.05f, 5.0f));
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
canvas.DrawLine(
arrowBegin.X + worldAxis.PerpendicularLeft.X * 2.0f,
arrowBegin.Y + worldAxis.PerpendicularLeft.Y * 2.0f,
bodyPos.Z,
arrowBegin.X + worldAxis.PerpendicularLeft.X * 2.0f + worldAxis.X * maxForceTemp,
arrowBegin.Y + worldAxis.PerpendicularLeft.Y * 2.0f + worldAxis.Y * maxForceTemp,
bodyPos.Z);
canvas.DrawLine(
arrowBegin.X + worldAxis.PerpendicularRight.X * 2.0f,
arrowBegin.Y + worldAxis.PerpendicularRight.Y * 2.0f,
bodyPos.Z,
arrowBegin.X + worldAxis.PerpendicularRight.X * 2.0f + worldAxis.X * maxForceTemp,
arrowBegin.Y + worldAxis.PerpendicularRight.Y * 2.0f + worldAxis.Y * maxForceTemp,
bodyPos.Z);
canvas.DrawLine(
arrowBegin.X,
arrowBegin.Y,
bodyPos.Z,
arrowBase.X,
arrowBase.Y,
bodyPos.Z);
canvas.DrawLine(
arrowBase.X,
arrowBase.Y,
bodyPos.Z,
arrowBase.X + arrowA.X,
arrowBase.Y + arrowA.Y,
bodyPos.Z);
canvas.DrawLine(
arrowBase.X,
arrowBase.Y,
bodyPos.Z,
arrowBase.X + arrowB.X,
arrowBase.Y + arrowB.Y,
bodyPos.Z);
}
示例9: DrawWorldAnchor
private void DrawWorldAnchor(Canvas canvas, RigidBody body, Vector2 anchor)
{
Vector3 colliderPos = body.GameObj.Transform.Pos;
float markerCircleRad = body.BoundRadius * 0.02f;
ColorRgba clr = this.JointColor;
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
canvas.FillCircle(
anchor.X,
anchor.Y,
colliderPos.Z,
markerCircleRad);
}
示例10: DrawLocalText
private void DrawLocalText(Canvas canvas, RigidBody body, string text, Vector2 pos, float baseAngle)
{
this.DrawLocalText(canvas, body, text, pos, Vector2.Zero, baseAngle);
}
示例11: SelBody
public SelBody(RigidBody obj)
{
this.bodyObj = obj != null ? obj.GameObj : null;
}
示例12: CreateRigidBodyShapeAction
public CreateRigidBodyShapeAction(RigidBody parent, params ShapeInfo[] obj) : this(parent, obj as IEnumerable<ShapeInfo>) {}
示例13: AddJoint
/// <summary>
/// Adds a new joint to the body.
/// </summary>
/// <param name="joint"></param>
public void AddJoint(JointInfo joint, RigidBody other = null)
{
if (joint == null) throw new ArgumentNullException("joint");
if (joint.ParentBody != null)
joint.ParentBody.RemoveJoint(joint);
joint.ParentBody = this;
joint.OtherBody = other;
if (this.joints == null) this.joints = new List<JointInfo>();
this.joints.Add(joint);
this.AwakeBody();
if (joint.OtherBody != null)
joint.OtherBody.AwakeBody();
joint.UpdateJoint();
}
示例14: FireBullet
private void FireBullet(RigidBody body, Transform transform, Vector2 localPos, float localAngle)
{
ShipBlueprint blueprint = this.blueprint.Res;
if (blueprint.BulletType == null) return;
Bullet bullet = blueprint.BulletType.Res.CreateBullet();
Vector2 recoilImpulse;
Vector2 worldPos = transform.GetWorldPoint(localPos);
bullet.Fire(this.owner, body.LinearVelocity, worldPos, transform.Angle + localAngle, out recoilImpulse);
body.ApplyWorldImpulse(recoilImpulse);
Scene.Current.AddObject(bullet.GameObj);
SoundInstance inst = null;
if (Player.AlivePlayers.Count() > 1)
inst = DualityApp.Sound.PlaySound3D(this.owner.WeaponSound, new Vector3(worldPos));
else
inst = DualityApp.Sound.PlaySound(this.owner.WeaponSound);
inst.Volume = MathF.Rnd.NextFloat(0.6f, 1.0f);
inst.Pitch = MathF.Rnd.NextFloat(0.9f, 1.11f);
}
示例15: DrawLocalLooseConstraint
private void DrawLocalLooseConstraint(Canvas canvas, RigidBody bodyA, RigidBody bodyB, Vector2 anchorA, Vector2 anchorB)
{
Vector3 bodyPosA = bodyA.GameObj.Transform.Pos;
Vector3 bodyPosB = bodyB.GameObj.Transform.Pos;
ColorRgba clr = this.JointColor;
Vector2 anchorAToWorld = bodyA.GameObj.Transform.GetWorldVector(anchorA);
Vector2 anchorBToWorld = bodyB.GameObj.Transform.GetWorldVector(anchorB);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
canvas.DrawDashLine(
bodyPosA.X + anchorAToWorld.X,
bodyPosA.Y + anchorAToWorld.Y,
bodyPosA.Z,
bodyPosB.X + anchorBToWorld.X,
bodyPosB.Y + anchorBToWorld.Y,
bodyPosB.Z);
}