Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Moving objects by changing its Transform

    • 0
    • 3
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 660
    Comment on it

    Transform are used for storing and manipulating objects Position , Rotation and Scale or Size .

    In this blog we will use transform to move an object.Moving an object by changing its transform does not require a Rigidbody, that way its hard to get collision events of the object .

    Below code can be used to move a object using transform :

    using UnityEngine;
    using System.Collections;
    
    public class BlockMovement : MonoBehaviour
     {
    
        private Vector3 pos ;
    
        void Update ()
        {
            if(Input.GetKey(KeyCode.UpArrow))
            {
                pos = this.transform.position;
                pos.z +=.1f;
                this.transform.position = pos;
            }
    
            if(Input.GetKey(KeyCode.DownArrow))
            {
                pos = this.transform.position;
                pos.z -=.1f;
                this.transform.position = pos;
            }
    
            if(Input.GetKey(KeyCode.LeftArrow))
            {
                    pos = this.transform.position;
                pos.x -=.1f;
                this.transform.position = pos;
            }
    
            if(Input.GetKey(KeyCode.RightArrow))
            {
                pos = this.transform.position;
                pos.x +=.1f;
                this.transform.position = pos;
            }
    
        }
    
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: