Search Unity

2.5d controller

Discussion in 'Physics' started by JeevanjotSingh, Jul 7, 2015.

  1. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    Hello,
    I am making a 2.5 d game , like with camera view on 2d and with 3d models (just explaining for some reasons ,i know you guys know about 2.5d) , Just have a problem about controlling ,i don't want to my character to go to x axis (in 2d i know it's x and y) in 2.5 d i have to lock z axis , but my player is 3d and it is looking at z so i need my player to go forward with it's look and i want to lock x axis so my player smoothly move to y(up/down) and z(forward/backward),I tried that -

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class force : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.  
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.         Time.timeScale = 0.5f;
    14.         if(Input.GetKey(KeyCode.UpArrow))
    15.            {
    16.             //GetComponent<Rigidbody>().velocity = new Vector2(0, 12);
    17.             GetComponent<Rigidbody>().AddForce(Vector3.up * 200,ForceMode.Acceleration);
    18.         }
    19.         if(Input.GetKey(KeyCode.DownArrow))
    20.         {
    21.             //GetComponent<Rigidbody>().velocity = new Vector2(0,-12);
    22.             GetComponent<Rigidbody>().AddForce(Vector3.down * 200,ForceMode.Acceleration);
    23.         }
    24.         if(Input.GetKey(KeyCode.LeftArrow))
    25.         {
    26.             //GetComponent<Rigidbody>().velocity = new Vector2(-12, 0);
    27.             GetComponent<Rigidbody>().AddForce(Vector3.back * 200,ForceMode.Acceleration);
    28.         }
    29.         if(Input.GetKey(KeyCode.RightArrow))
    30.         {
    31.             //GetComponent<Rigidbody>().velocity = new Vector2(12, 0);
    32.             GetComponent<Rigidbody>().AddForce(Vector3.forward * 200,ForceMode.Acceleration);
    33.         }
    34.         }
    35. }
    36.  

    but it won't work at all , even if i tried to lock z with vector 2 but it still move to z but i want to lock x , and i tired vector 3 but it still won't work , it sill moving to x . any help, thanks .