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

Just getting started, very confused

Discussion in 'Getting Started' started by watisap88, Oct 7, 2018.

  1. watisap88

    watisap88

    Joined:
    Oct 7, 2018
    Posts:
    1
    I am making a very simple dodge bricks game and when you hit one I want the camera o look at the level so you can see your trail.
    I have tried this
    Code (CSharp):
    1. if (Input.GetKey("w"))
    2.         {
    3.             transform.position.Set(0, 50, 40);
    4.             transform.rotation.Set(90, 0, 0, 0);
    5.         }
    and multiple other things; however, when I disable my follow player script and enable this one the camera just freezes and does not go to my coordanates. But when I hit space(my reset level botton) the follow player script reactivates and continue to follow the player.

    thank you for the help
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,419
    This does not query the W key, but an input binding named "w" in the InputManager, as described in the documentation:
    https://docs.unity3d.com/ScriptReference/Input.GetKey.html

    If you want to hard-code the W key, you should be able to do this with:
    Code (CSharp):
    1. if (Input.GetKey(KeyCode.W))
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    That's all true, but in fact if there is no input binding named "w", then it will respond to the W key. So this is not the problem. (Verify this by adding a Debug.Log inside the if statement.)

    @watisap88, I don't understand the question. The script as shown looks like it should make the camera freeze — either at its previous position, or at the new position/orientation. You don't yet understand quaternions, and should probably be using
    transform.eulerAngles = new Vector3(90, 0, 0)
    instead, but that seems like a minor issue.

    Can you explain better what you want this script to do, and how that differs from what it's actually doing?
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Today I learned
    Vector3.Set
    exists.
     
    guetta18 and DaemonicDreams like this.
  5. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    I had no idea that was a thing
     
  6. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    try
    Code (CSharp):
    1. if (Input.GetKey(KeyCode.W))