UnityEngine.Rigidbody2D.AddForce(UnityEngine.Vector2, UnityEngine.ForceMode2D)

Here are the examples of the csharp api UnityEngine.Rigidbody2D.AddForce(UnityEngine.Vector2, UnityEngine.ForceMode2D) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 View Source File : Player.cs
License : MIT License
Project Creator : ZuBsPaCe

private void PerformUpdate()
        {
            switch (_movementType)
            {
                case MovementType.Transform_Position:
                {
                    _startInterpolationPos = transform.position;

                    Vector3 position = transform.position;
                    position.x += Time.deltaTime * _velocity;

                    HandleReversal(ref position);

                    transform.position = position;

                    _endInterpolationPos = transform.position;
                    break;
                }

                case MovementType.Rigidbody_Position:
                {
                    _startInterpolationPos = _rigidbody.position;

                    Vector3 position = _rigidbody.position;
                    position.x += Time.deltaTime * _velocity;

                    HandleReversal(ref position);

                    _rigidbody.position = position;

                    _endInterpolationPos = _rigidbody.position;
                    break;
                }

                case MovementType.Rigidbody_MovePosition:
                {
                    _startInterpolationPos = _rigidbody.position;

                    Vector3 position = _rigidbody.position;
                    position.x += Time.deltaTime * _velocity;

                    HandleReversal(ref position);

                    _rigidbody.MovePosition(position);

                    _endInterpolationPos = _rigidbody.position;
                    break;
                }

                case MovementType.Rigidbody_CustomMove:
                {
                    _startInterpolationPos = _rigidbody.position;

                    Vector3 position = _rigidbody.position;
                    position.x += Time.deltaTime * _velocity;

                    HandleReversal(ref position);

                    _rigidbody.CustomMove(position);

                    _endInterpolationPos = _rigidbody.position;
                    break;
                }

                case MovementType.Rigidbody_SetVelocity:
                {
                    _startInterpolationPos = _rigidbody.position;

                    Vector3 position = _rigidbody.position;
                    if (HandleReversal(ref position))
                    {
                        _rigidbody.position = position;
                    }

                    _rigidbody.velocity = new Vector2(_velocity, 0);

                    _endInterpolationPos = _startInterpolationPos + _rigidbody.velocity * Time.deltaTime;
                    break;
                }

                case MovementType.Rigidbody_AddVelocity:
                case MovementType.Rigidbody_AddForce:
                case MovementType.Rigidbody_AddImpulse:
                {
                    _startInterpolationPos = _rigidbody.position;

                    float change = _addForcePidController.Update(_velocity - _rigidbody.velocity.x, Time.deltaTime);

                    if (_movementType == MovementType.Rigidbody_AddVelocity)
                    {
                        _rigidbody.velocity += new Vector2(change * Time.deltaTime, 0);
                    }
                    else if (_movementType == MovementType.Rigidbody_AddForce)
                    {
                        _rigidbody.AddForce(new Vector2(change, 0), ForceMode2D.Force);
                    }
                    else if (_movementType == MovementType.Rigidbody_AddImpulse)
                    {
                        _rigidbody.AddForce(new Vector2(change * Time.deltaTime, 0), ForceMode2D.Impulse);
                    }

                    Vector3 position = _rigidbody.position;
                    if (HandleReversal(ref position))
                    {
                        _rigidbody.position = position;
                        _rigidbody.velocity = -_rigidbody.velocity;
                    }

                    _endInterpolationPos = _startInterpolationPos + _rigidbody.velocity * Time.deltaTime;
                    break;
                }

                case MovementType.CharacterController_Move:
                {
                    _startInterpolationPos = transform.position;

                    Vector3 position = transform.position;
                    position.x += Time.deltaTime * _velocity;

                    HandleReversal(ref position);

                    _characterController.Move(new Vector3(Time.deltaTime * _velocity, 0, 0));

                    _endInterpolationPos = transform.position;

                    break;
                }
            }
        }