public static void Simulate(PlayerSimulationConfig config, IRigidbody body, PlayerInput input) { Vector3 forward = body.State.Rotation * Vector3.forward; Vector3 up = body.State.Rotation * Vector3.up; float speedFactor = Mathf.Clamp01((body.State.Velocity.magnitude - 5f) / 10f); float forwardDot = Mathf.Clamp01(1f - forward.y); float rollAngle = MathUtils.AngleAroundAxis(up, Vector3.up, forward); float rollInducedBank = Mathf.Pow(Mathf.Clamp01(Mathf.Abs(rollAngle) * MathUtils.OneOver180 * forwardDot * speedFactor), 1.5f) * Mathf.Sign(rollAngle); float rollStabilizer = Mathf.Pow(Mathf.Clamp01(Mathf.Abs(rollAngle) * MathUtils.OneOver180 * forwardDot), 2f) * Mathf.Sign(rollAngle); rollStabilizer *= 1f - Mathf.Abs(input.Roll); body.AddRelativeTorque(new Vector3( input.Pitch * config.RotationSpeed.x + Mathf.Abs(rollInducedBank) * -0.66f * config.RotationSpeed.x, input.Yaw * config.RotationSpeed.y + rollInducedBank * 0.66f * config.RotationSpeed.y, input.Roll * -config.RotationSpeed.z + rollStabilizer * 0.66f * config.RotationSpeed.z), ForceMode.Force); float maxThrust = input.Boost ? 50f : 20f; body.AddRelativeForce(Vector3.forward * maxThrust * input.Thrust, ForceMode.Force); Vector3 offHeadingVelocity = body.State.Velocity - Vector3.Project(body.State.Velocity, forward); Vector3 dampening = offHeadingVelocity * -2.0f; Vector3 conserved = offHeadingVelocity.magnitude * forward * 0.33f; body.AddForce(dampening + conserved + Vector3.down, ForceMode.Force); }
public void ReplaceRigidbody(IRigidbody newValue) { var index = GameComponentsLookup.Rigidbody; var component = CreateComponent <RigidbodyComponent>(index); component.Value = newValue; ReplaceComponent(index, component); }
public void AddRigidbody(IRigidbody newValue) { var index = GameComponentsLookup.Rigidbody; var component = CreateComponent <RigidbodyComponent>(index); component.value = newValue; AddComponent(index, component); }
//This isnt the best for our PlayerRigidbody since our PlayerRigidbody runs in update and this runs in FixedUpdate. void OnTriggerStay(Collider collider) { IRigidbody rigidbody = collider.GetComponent <IRigidbody>(); if (rigidbody != null) { rigidbody.AddForce(direction * force, forceMode); } }
/// <summary> /// Removes a particular rigidbody from the world /// </summary> /// <param name="rigidbody"></param> public void RemoveRigidbody(IRigidbody rigidbody) { var bepuShape = rigidbody.Shape as IBEPUShape; if (bepuShape != null) { this.space.Remove(bepuShape); } }
protected override void Awake() { _rb = GetComponent <Rigidbody>(); _au = GetComponent <AudioSource>(); _vehicle = GetComponent <Vehicle>(); _pursuit = GetComponent <Pursuit>(); _pursuit.target = Target.GetComponent <Vehicle>(); _vehicle.MaxSpeed = 130; Transform.Rotation = (float)Math.Atan2(_rb.velocity.X, -_rb.velocity.Y); }
public void Execute() { var entities = m_MovingEntities.GetEntities(); foreach (GameEntity entity in entities) { if (entity.hasPhysics) { if (entity.physics.Rigid.IsKinematic) { float physicalYSpeed = entity.physics.Rigid.Velocity.y; Vector3 velocity = entity.movement.Velocity; Vector3 offset = entity.physics.Offset; IRigidbody rigid = entity.physics.Rigid; Vector3 skillVelocity = SkillSystem.Instance.GetSkillVelocity(entity); Vector3 buffVelocity = BuffSystem.Instance.GetBuffVelocity(entity); if (skillVelocity.IsNearlyZero() && buffVelocity.IsNearlyZero()) { rigid.Velocity = velocity + Vector3.up * physicalYSpeed; } else { rigid.Velocity = velocity + skillVelocity + buffVelocity; } rigid.Rotation = Quaternion.Euler(0, Mathf.Rad2Deg * entity.rotation.Value, 0); } Vector3 position = entity.physics.Rigid.Position; entity.ReplacePosition(position); } } }
public override void OnLoad() { _ship = Agent.GetComponent <Ship>(); _rb = Agent.GetComponent <Rigidbody>(); }
public static Point GetPoint(this IRigidbody element) => new Point(Canvas.GetLeft(element as UIElement), Canvas.GetTop(element as UIElement));
public GenericGrabbable(IRigidbody rigidbody) { Rigidbody = rigidbody; }
public static double GetX(this IRigidbody element) => Canvas.GetLeft(element as UIElement);
protected override void Awake() { _fsm = GetComponent <FSM>(); _rb = GetComponent <Rigidbody>(); Seek = GetComponent <Seek>(); }
public static double GetTop(this IRigidbody element) => Canvas.GetTop(element as UIElement);
public static void SetRight(this IRigidbody element, double right) => Canvas.SetLeft(element as UIElement, right - element.Rigidbody.Width);
public static double GetRight(this IRigidbody element) => Canvas.GetLeft(element as UIElement) + element.Rigidbody.Width;
public static void SetLeft(this IRigidbody element, double left) => Canvas.SetLeft(element as UIElement, left);
public static void SetY(this IRigidbody element, double y) => Canvas.SetTop(element as UIElement, y);
public static void SetX(this IRigidbody element, double x) => Canvas.SetLeft(element as UIElement, x);
public static double GetBottom(this IRigidbody element) => Canvas.GetTop(element as UIElement) + element.Rigidbody.Width;
protected override void Awake() { _rb = GetComponent <IRigidbody>(); }
protected override void Start() { _rb = GetComponent <IRigidbody>(); _direction = Transform.Up; }
public static void SetBottom(this IRigidbody element, double bottom) => Canvas.SetTop(element as UIElement, bottom - element.Rigidbody.Height);
public void BeforeEveryTest() { _hand = new GameObject(); _fixedJoint = _hand.AddComponent <FixedJoint>(); _unityRigidbody = Substitute.For <IRigidbody>(); }
public static void SetTop(this IRigidbody element, double top) => Canvas.SetTop(element as UIElement, top);
public static void SetPoint(this IRigidbody element, Point value) { Canvas.SetLeft(element as UIElement, value.X); Canvas.SetTop(element as UIElement, value.Y); }