How to Move Make Objects by Adding Force in Unity

Posted by Sachin Joshi
3
Nov 30, 2015
179 Views
There are two methods to make object move in unity:

1. By changing its Transform (Position).
2. By adding Force by using AddForce() method.
 download


In this blog I have mentioned, how we can make object move by adding force. Force and Velocity both are component of Physics. So, to make our gameobject come under influence of Physics we must attach a rigid body to it and then we can code it to move by adding force in different direction. Below is the script for your reference.

  • using UnityEngine;
  • using System.Collections;
  • public class BallScript : MonoBehaviour
  • {
  • void Update ()
  • {
  • if (Input.GetKey (KeyCode.UpArrow))
  • {
  • this.gameObject.rigidbody.AddForce(0,0,10,ForceMode.Acceleration);
  • }
  • if (Input.GetKey (KeyCode.DownArrow))
  • .................

  • See more at:How to Move Make Objects by Adding Force in Unity

    You can check more informative blogs and tutorials at android development blogs section and can also browse the android developer forum for posting and viewing latest questions on android development.
    Comments
    avatar
    Please sign in to add comment.