Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

I do I rest move direction with FPS controller?

Discussion in 'Scripting' started by davisdonarts, Jun 6, 2018.

  1. davisdonarts

    davisdonarts

    Joined:
    Dec 12, 2017
    Posts:
    27
    I am making a art game where the shapes can move and instantiate. But the directions wont switch to a local direction? I made 6 box colliders that manages to switch directions. When the stick collider touches the Back collider for example it switches from forward to backward direction of the ghost selection. But I don't how to code that?Do you guys?

    C#
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GhostMove : MonoBehaviour {
    6.  
    7.     public AudioSource moveGhostSound;
    8.     public AudioSource liftGhostSound;
    9.  
    10.     // Update is called once per frame
    11.     void Update ()
    12.     {
    13.         if (Input.GetKeyDown (KeyCode.Keypad8))
    14.         {
    15.             transform.Translate (0.0f, 0.0f, 1.0f);
    16.             moveGhostSound.Play ();
    17.         }
    18.         if (Input.GetKeyDown (KeyCode.Keypad2))
    19.         {
    20.             transform.Translate (0.0f, 0.0f, -1.0f);
    21.             moveGhostSound.Play ();
    22.         }
    23.         if (Input.GetKeyDown (KeyCode.Keypad6))
    24.         {
    25.             transform.Translate (1.0f, 0.0f, 0.0f);
    26.             moveGhostSound.Play ();
    27.         }
    28.         if (Input.GetKeyDown (KeyCode.Keypad4))
    29.         {
    30.             transform.Translate (-1.0f, 0.0f, 0.0f);
    31.             moveGhostSound.Play ();
    32.         }
    33.         if (Input.GetKeyDown (KeyCode.KeypadPlus))
    34.         {
    35.             transform.Translate (0.0f, 1.0f, 0.0f);
    36.             liftGhostSound.Play ();
    37.         }
    38.         if (Input.GetKeyDown (KeyCode.Keypad5))
    39.         {
    40.             transform.Translate (0.0f, -1.0f, 0.0f);
    41.             liftGhostSound.Play ();
    42.         }
    43.     }
    44. }
    45.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,599
    Not sure what you're asking. Transform.Translate takes world coordinates. If you want to put in relative coordinates, then you can use the transform shortcut properties: transform.forward, transform.up, transform.right and their negatives.
     
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You can translate in Space.World or Space.Self.

    That said, I'm also not sure what this question is asking, either.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,599
    One is safe for work, one is not.