Articles

How to Move Make Objects by Adding Force in Unity

by Sachin Joshi SEO/ SMO Consult
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.

    Sponsor Ads


    About Sachin Joshi Innovator   SEO/ SMO Consult

    37 connections, 0 recommendations, 89 honor points.
    Joined APSense since, May 14th, 2015, From Dehradun, India.

    Created on Dec 31st 1969 18:00. Viewed 0 times.

    Comments

    No comment, be the first to comment.
    Please sign in before you comment.