コード例 #1
0
    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);
    }
コード例 #2
0
    public void ReplaceRigidbody(IRigidbody newValue)
    {
        var index     = GameComponentsLookup.Rigidbody;
        var component = CreateComponent <RigidbodyComponent>(index);

        component.Value = newValue;
        ReplaceComponent(index, component);
    }
コード例 #3
0
    public void AddRigidbody(IRigidbody newValue)
    {
        var index     = GameComponentsLookup.Rigidbody;
        var component = CreateComponent <RigidbodyComponent>(index);

        component.value = newValue;
        AddComponent(index, component);
    }
コード例 #4
0
    //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);
        }
    }
コード例 #5
0
        /// <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);
            }
        }
コード例 #6
0
    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);
    }
コード例 #7
0
        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);
                }
            }
        }
コード例 #8
0
 public override void OnLoad()
 {
     _ship = Agent.GetComponent <Ship>();
     _rb   = Agent.GetComponent <Rigidbody>();
 }
コード例 #9
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static Point GetPoint(this IRigidbody element)
 => new Point(Canvas.GetLeft(element as UIElement), Canvas.GetTop(element as UIElement));
コード例 #10
0
 public GenericGrabbable(IRigidbody rigidbody)
 {
     Rigidbody = rigidbody;
 }
コード例 #11
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static double GetX(this IRigidbody element)
 => Canvas.GetLeft(element as UIElement);
コード例 #12
0
ファイル: Ship.cs プロジェクト: andrecosta/Mini-Prey
 protected override void Awake()
 {
     _fsm = GetComponent <FSM>();
     _rb  = GetComponent <Rigidbody>();
     Seek = GetComponent <Seek>();
 }
コード例 #13
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static double GetTop(this IRigidbody element)
 => Canvas.GetTop(element as UIElement);
コード例 #14
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static void SetRight(this IRigidbody element, double right)
 => Canvas.SetLeft(element as UIElement, right - element.Rigidbody.Width);
コード例 #15
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static double GetRight(this IRigidbody element)
 => Canvas.GetLeft(element as UIElement) + element.Rigidbody.Width;
コード例 #16
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static void SetLeft(this IRigidbody element, double left)
 => Canvas.SetLeft(element as UIElement, left);
コード例 #17
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static void SetY(this IRigidbody element, double y)
 => Canvas.SetTop(element as UIElement, y);
コード例 #18
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static void SetX(this IRigidbody element, double x)
 => Canvas.SetLeft(element as UIElement, x);
コード例 #19
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static double GetBottom(this IRigidbody element)
 => Canvas.GetTop(element as UIElement) + element.Rigidbody.Width;
コード例 #20
0
 protected override void Awake()
 {
     _rb = GetComponent <IRigidbody>();
 }
コード例 #21
0
ファイル: Vehicle.cs プロジェクト: andrecosta/Mini-Prey
 protected override void Start()
 {
     _rb        = GetComponent <IRigidbody>();
     _direction = Transform.Up;
 }
コード例 #22
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static void SetBottom(this IRigidbody element, double bottom)
 => Canvas.SetTop(element as UIElement, bottom - element.Rigidbody.Height);
コード例 #23
0
 public void BeforeEveryTest()
 {
     _hand           = new GameObject();
     _fixedJoint     = _hand.AddComponent <FixedJoint>();
     _unityRigidbody = Substitute.For <IRigidbody>();
 }
コード例 #24
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static void SetTop(this IRigidbody element, double top)
 => Canvas.SetTop(element as UIElement, top);
コード例 #25
0
ファイル: IRigidBody.cs プロジェクト: waynejhou/WPFin3D
 public static void SetPoint(this IRigidbody element, Point value)
 {
     Canvas.SetLeft(element as UIElement, value.X);
     Canvas.SetTop(element as UIElement, value.Y);
 }