UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)

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

9 Examples 7

19 View Source File : TriggerColliderWeapon.cs
License : GNU General Public License v3.0
Project Creator : aelariane

private void napeMeat(Vector3 vkill, Transform replacedan)
    {
        Transform transform = replacedan.transform.Find("Amarture/Core/Controller_Body/hip/spine/chest/neck");
        GameObject gameObject = Pool.Enable("replacedanNapeMeat", transform.position, transform.rotation);//(GameObject)UnityEngine.Object.Instantiate(CacheResources.Load("replacedanNapeMeat"), transform.position, transform.rotation);
        gameObject.transform.localScale = replacedan.localScale;
        gameObject.rigidbody.AddForce(vkill.normalized * 15f, ForceMode.Impulse);
        gameObject.rigidbody.AddForce(-replacedan.forward * 10f, ForceMode.Impulse);
        gameObject.rigidbody.AddTorque(new Vector3((float)UnityEngine.Random.Range(-100, 100), (float)UnityEngine.Random.Range(-100, 100), (float)UnityEngine.Random.Range(-100, 100)), ForceMode.Impulse);
    }

19 View Source File : Horse.cs
License : GNU General Public License v3.0
Project Creator : aelariane

private void LateUpdate()
    {
        if (Owner == null && BasePV.IsMine)
        {
            PhotonNetwork.Destroy(gameObject);
            return;
        }

        switch (State)
        {
            case HorseState.Mounted:
                {
                    if (this.Owner == null)
                    {
                        this.Unmounted();
                        return;
                    }

                    Owner.baseT.position = baseT.position + heroOffsetVector;
                    Owner.baseT.rotation = baseR.rotation;
                    Owner.baseR.velocity = baseR.velocity;

                    if (controller.targetDirection == -874f)
                    {
                        this.ToIdleAnimation();
                        if (baseR.velocity.magnitude > 15f)
                        {
                            if (!Owner.baseA.IsPlaying("horse_run"))
                            {
                                Owner.CrossFade("horse_run", 0.1f);
                            }
                        }
                        else if (!Owner.baseA.IsPlaying("horse_idle"))
                        {
                            Owner.CrossFade("horse_idle", 0.1f);
                        }
                    }
                    else
                    {
                        base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, this.controller.targetDirection, 0f), 100f * Time.deltaTime / (base.rigidbody.velocity.magnitude + 20f));
                        if (this.controller.isWALKDown)
                        {
                            baseR.AddForce(baseT.Forward() * this.speed * 0.6f, ForceMode.Acceleration);
                            if (baseR.velocity.magnitude >= this.speed * 0.6f)
                            {
                                baseR.AddForce(-this.speed * 0.6f * baseR.velocity.normalized, ForceMode.Acceleration);
                            }
                        }
                        else
                        {
                            baseR.AddForce(baseT.Forward() * this.speed, ForceMode.Acceleration);
                            if (baseR.velocity.magnitude >= this.speed)
                            {
                                baseR.AddForce(-this.speed * baseR.velocity.normalized, ForceMode.Acceleration);
                            }
                        }
                        if (baseR.velocity.magnitude > 8f)
                        {
                            if (!baseA.IsPlaying("horse_Run"))
                            {
                                this.CrossFade("horse_Run", 0.1f);
                            }
                            if (!this.Owner.baseA.IsPlaying("horse_run"))
                            {
                                this.Owner.CrossFade("horse_run", 0.1f);
                            }
                            if (!this.dustParticle.enableEmission)
                            {
                                this.dustParticle.enableEmission = true;
                                BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                                {
                        true
                                });
                            }
                        }
                        else
                        {
                            if (!baseA.IsPlaying("horse_WALK"))
                            {
                                this.CrossFade("horse_WALK", 0.1f);
                            }
                            if (!this.Owner.baseA.IsPlaying("horse_idle"))
                            {
                                this.Owner.baseA.CrossFade("horse_idle", 0.1f);
                            }
                            if (this.dustParticle.enableEmission)
                            {
                                this.dustParticle.enableEmission = false;
                                BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                                {
                                    false
                                });
                            }
                        }
                    }

                    if ((this.controller.isAttackDown || this.controller.isAttackIIDown) && this.IsGrounded())
                    {
                        baseR.AddForce(Vectors.up * 25f, ForceMode.VelocityChange);
                    }
                }
                break;

            case HorseState.Follow:
                {
                    if (this.Owner == null)
                    {
                        this.Unmounted();
                        return;
                    }

                    if (baseR.velocity.magnitude > 8f)
                    {
                        if (!baseA.IsPlaying("horse_Run"))
                        {
                            this.CrossFade("horse_Run", 0.1f);
                        }
                        if (!this.dustParticle.enableEmission)
                        {
                            this.dustParticle.enableEmission = true;
                            BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                            {
                        true
                            });
                        }
                    }
                    else
                    {
                        if (!baseA.IsPlaying("horse_WALK"))
                        {
                            this.CrossFade("horse_WALK", 0.1f);
                        }
                        if (this.dustParticle.enableEmission)
                        {
                            this.dustParticle.enableEmission = false;
                            BasePV.RPC("setDust", PhotonTargets.Others, new object[]
                            {
                                false
                            });
                        }
                    }

                    float num = -Mathf.DeltaAngle(FengMath.GetHorizontalAngle(baseT.position, this.setPoint), base.gameObject.transform.rotation.eulerAngles.y - 90f);
                    base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, base.gameObject.transform.rotation.eulerAngles.y + num, 0f), 200f * Time.deltaTime / (baseR.velocity.magnitude + 20f));
                    if (Vector3.Distance(this.setPoint, baseT.position) < 20f)
                    {
                        baseR.AddForce(baseT.Forward() * this.speed * 0.7f, ForceMode.Acceleration);
                        if (baseR.velocity.magnitude >= this.speed)
                        {
                            baseR.AddForce(-this.speed * 0.7f * baseR.velocity.normalized, ForceMode.Acceleration);
                        }
                    }
                    else
                    {
                        baseR.AddForce(base.transform.Forward() * this.speed, ForceMode.Acceleration);
                        if (baseR.velocity.magnitude >= this.speed)
                        {
                            baseR.AddForce(-this.speed * baseR.velocity.normalized, ForceMode.Acceleration);
                        }
                    }
                    this.timeElapsed += Time.deltaTime;
                    if (this.timeElapsed > 0.6f)
                    {
                        this.timeElapsed = 0f;
                        if (Vector3.Distance(this.Owner.baseT.position, this.setPoint) > 20f)
                        {
                            this.Followed();
                        }
                    }
                    if (Vector3.Distance(this.Owner.baseT.position, baseT.position) < 5f)
                    {
                        this.Unmounted();
                    }
                    if (Vector3.Distance(this.setPoint, baseT.position) < 5f)
                    {
                        this.Unmounted();
                    }
                    this.awayTimer += Time.deltaTime;
                    if (this.awayTimer > 6f)
                    {
                        this.awayTimer = 0f;
                        if (Physics.Linecast(baseT.position + Vectors.up, this.Owner.baseT.position + Vectors.up, Layers.Ground.value))
                        {
                            baseT.position = new Vector3(this.Owner.baseT.position.x, this.GetHeight(this.Owner.baseT.position + Vectors.up * 5f), this.Owner.baseT.position.z);
                        }
                    }
                }
                break;

            case HorseState.Idle:
                {
                    this.ToIdleAnimation();
                    if (this.Owner != null && Vector3.Distance(this.Owner.baseT.position, baseT.position) > 20f)
                    {
                        this.Followed();
                    }
                }
                break;
        }
        baseR.AddForce(new Vector3(0f, -50f * baseR.mreplaced, 0f));
    }

19 View Source File : RigidbodyFirstPersonController.cs
License : MIT License
Project Creator : Donut-Studios

private void FixedUpdate()
        {
            GroundCheck();
            Vector2 input = GetInput();

            if ((Mathf.Abs(input.x) > float.Epsilon || Mathf.Abs(input.y) > float.Epsilon) && (advancedSettings.airControl || m_IsGrounded))
            {
                // always move along the camera forward as it is the direction that it being aimed at
                Vector3 desiredMove = cam.transform.forward*input.y + cam.transform.right*input.x;
                desiredMove = Vector3.ProjectOnPlane(desiredMove, m_GroundContactNormal).normalized;

                desiredMove.x = desiredMove.x*movementSettings.CurrentTargetSpeed;
                desiredMove.z = desiredMove.z*movementSettings.CurrentTargetSpeed;
                desiredMove.y = desiredMove.y*movementSettings.CurrentTargetSpeed;
                if (m_RigidBody.velocity.sqrMagnitude <
                    (movementSettings.CurrentTargetSpeed*movementSettings.CurrentTargetSpeed))
                {
                    m_RigidBody.AddForce(desiredMove*SlopeMultiplier(), ForceMode.Impulse);
                }
            }

            if (m_IsGrounded)
            {
                m_RigidBody.drag = 5f;

                if (m_Jump)
                {
                    m_RigidBody.drag = 0f;
                    m_RigidBody.velocity = new Vector3(m_RigidBody.velocity.x, 0f, m_RigidBody.velocity.z);
                    m_RigidBody.AddForce(new Vector3(0f, movementSettings.JumpForce, 0f), ForceMode.Impulse);
                    m_Jumping = true;
                }

                if (!m_Jumping && Mathf.Abs(input.x) < float.Epsilon && Mathf.Abs(input.y) < float.Epsilon && m_RigidBody.velocity.magnitude < 1f)
                {
                    m_RigidBody.Sleep();
                }
            }
            else
            {
                m_RigidBody.drag = 0f;
                if (m_PreviouslyGrounded && !m_Jumping)
                {
                    StickToGroundHelper();
                }
            }
            m_Jump = false;
        }

19 View Source File : SimpleCharacterControl.cs
License : MIT License
Project Creator : harshitjuneja

private void JumpingAndLanding()
    {
        bool jumpCooldownOver = (Time.time - m_jumpTimeStamp) >= m_minJumpInterval;

        if (jumpCooldownOver && m_isGrounded && Input.GetKey(KeyCode.Space))
        {
            m_jumpTimeStamp = Time.time;
            m_rigidBody.AddForce(Vector3.up * m_jumpForce, ForceMode.Impulse);
        }

        if (!m_wasGrounded && m_isGrounded)
        {
            m_animator.SetTrigger("Land");
        }

        if (!m_isGrounded && m_wasGrounded)
        {
            m_animator.SetTrigger("Jump");
        }
    }

19 View Source File : AttackTrigger.cs
License : MIT License
Project Creator : Interactml

void OnTriggerEnter(Collider other)
        {
            if (other.isTrigger) return;                                                //just collapse when is a collider what we are hitting
            enemy = other.GetComponentInParent<IMDamagable>();                          //Get the Animal on the Other collider

            if (enemy != null) //if the other does'nt have the animal script skip
            {
               
                if (myAnimal.GetComponent<IMDamagable>() == enemy) return;                      //Don't Hit yourself

                Vector3 direction = myAnimal.transform.position - other.bounds.center;       //Calculate the direction of the attack

                DamageValues DV = new DamageValues(direction, damageMultiplier * (myAnimal ? myAnimal.attackStrength : 1));

             

                enemy.getDamaged(DV);
            }
            else
            {
                if (other.attachedRigidbody && PushForce != 0)        //If the other has a riggid body and it can be pushed
                {
                    other.attachedRigidbody.AddForce((other.transform.position- transform.position).normalized * PushForce, ForceMode.VelocityChange);
                }
            }
        }

19 View Source File : JumpNoRootBehaviour.cs
License : MIT License
Project Creator : Interactml

override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            animal = animator.GetComponent<Animal>();
            rb = animator.GetComponent<Rigidbody>();

            animal.InAir(true);
            animal.SetIntID(0);
            animal.OnJump.Invoke();     //Invoke that the Animal is Jumping

            animal.RootMotion = false;

            Vector3 JumpVector = (Vector3.up * JumpMultiplier * animal.JumpHeightMultiplier) + (animator.transform.forward * ForwardMultiplier * animal.AirForwardMultiplier);

            rb.AddForce(JumpVector, ForceMode.VelocityChange); //Jump Up
        }

19 View Source File : Ball.cs
License : MIT License
Project Creator : joanby

public void Move(Vector3 moveDirection, bool jump)
        {
            // If using torque to rotate the ball...
            if (m_UseTorque)
            {
                // ... add torque around the axis defined by the move direction.
                m_Rigidbody.AddTorque(new Vector3(moveDirection.z, 0, -moveDirection.x)*m_MovePower);
            }
            else
            {
                // Otherwise add force in the move direction.
                m_Rigidbody.AddForce(moveDirection*m_MovePower);
            }

            // If on the ground and jump is pressed...
            if (Physics.Raycast(transform.position, -Vector3.up, k_GroundRayLength) && jump)
            {
                // ... add force in upwards.
                m_Rigidbody.AddForce(Vector3.up*m_JumpPower, ForceMode.Impulse);
            }
        }

19 View Source File : GrabbingHand.cs
License : Apache License 2.0
Project Creator : OOXXXXOO

protected void ContinueSoftPinch() {
    Quaternion target_rotation = palm_rotation_ * rotation_from_palm_;

    Vector3 target_position = filtered_pinch_position_ + target_rotation * object_pinch_offset_;
    Vector3 delta_position = target_position - active_object_.transform.position;

    float strength = (releaseBreakDistance - delta_position.magnitude) / releaseBreakDistance;
    strength = releaseStrengthCurve.Evaluate(strength);
    active_object_.GetComponent<Rigidbody>().AddForce(delta_position.normalized * strength * positionFiltering,
                                      ForceMode.Acceleration);

    Quaternion delta_rotation = target_rotation *
                                Quaternion.Inverse(active_object_.transform.rotation);

    float angle = 0.0f;
    Vector3 axis = Vector3.zero;
    delta_rotation.ToAngleAxis(out angle, out axis);

    active_object_.GetComponent<Rigidbody>().AddTorque(strength * rotationFiltering * angle * axis,
                                       ForceMode.Acceleration);
  }

19 View Source File : UnityEngine_RigidbodyWrap.cs
License : MIT License
Project Creator : XINCGer

[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
	static int AddForce(IntPtr L)
	{
		try
		{
			int count = LuaDLL.lua_gettop(L);

			if (count == 2)
			{
				UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject<UnityEngine.Rigidbody>(L, 1);
				UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2);
				obj.AddForce(arg0);
				return 0;
			}
			else if (count == 3)
			{
				UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject<UnityEngine.Rigidbody>(L, 1);
				UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2);
				UnityEngine.ForceMode arg1 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 3, typeof(UnityEngine.ForceMode));
				obj.AddForce(arg0, arg1);
				return 0;
			}
			else if (count == 4)
			{
				UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject<UnityEngine.Rigidbody>(L, 1);
				float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
				float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
				float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
				obj.AddForce(arg0, arg1, arg2);
				return 0;
			}
			else if (count == 5)
			{
				UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject<UnityEngine.Rigidbody>(L, 1);
				float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
				float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
				float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
				UnityEngine.ForceMode arg3 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 5, typeof(UnityEngine.ForceMode));
				obj.AddForce(arg0, arg1, arg2, arg3);
				return 0;
			}
			else
			{
				return LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Rigidbody.AddForce");
			}
		}
		catch (Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}