Files
RobustToolbox/Robust.Client/GameObjects/Components/Physics/PhysicsComponent.cs
T
AcruidandPieter-Jan Briers f2eb035ed8 Physics Shapes (#847)
* Adds a new IPhysicsShape object where you can define what collisions shape a PhysBody has.
AABB is now accessed through the PhysicsShape, so the BoundingBoxComponent is not required.

* Default PhysShape now copies the AABB of the BoundingBoxComponent.

* Fixed issue with serialization of PhysShapeAabbComp.

* Spatial queries now use ICollidableComponent instead of BoundingBoxComponent.
showbb now draws entities using the obsolete BoundingBoxComponent in Aqua.

* Renamed PhysShapeAabbComp to PhysShapeAabb.
Removed BoundingBoxComponent.

* Default CollidableComponent does not collide with anything now.

* Renamed ICollidable to IPhysBody.
Moved ICollidable to the Robust.Shared/Physics namespace.

* PhysShapes are now a collection of primitive shapes that contribute to the whole PhysBody.
ObjectSerializer.DataField can now deal with abstract types using YAML tags.

* Added LocalBounds property to ClickableComponent.
Added state to ClickableComponent.

* Added a Rectangle physics shape.

* ClickableComponent now actually checks that a click is inside its bounds.

* Reverted the addition of a try/catch around map loading. Any errors can propagate to the code trying to load the map again.
2019-09-03 22:06:50 +02:00

48 lines
1.5 KiB
C#

using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables;
namespace Robust.Client.GameObjects
{
/// <summary>
/// Contains physical properties of the entity. This component registers the entity
/// in the physics system as a dynamic ridged body object that has physics. This behavior overrides
/// the BoundingBoxComponent behavior of making the entity static.
/// </summary>
internal class PhysicsComponent : Component
{
/// <inheritdoc />
public override string Name => "Physics";
/// <inheritdoc />
public override uint? NetID => NetIDs.PHYSICS;
/// <inheritdoc />
public override Type StateType => typeof(PhysicsComponentState);
/// <summary>
/// Current mass of the entity in kg.
/// </summary>
[ViewVariables]
public float Mass { get; private set; }
/// <summary>
/// Current velocity of the entity.
/// </summary>
[ViewVariables]
public Vector2 Velocity { get; private set; }
/// <inheritdoc />
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
if (curState == null)
return;
var newState = (PhysicsComponentState)curState;
Mass = newState.Mass / 1000f; // gram to kilogram
Velocity = newState.Velocity;
}
}
}