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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Getting help with my code.

Discussion in 'Scripting' started by pebble225, May 19, 2015.

  1. pebble225

    pebble225

    Joined:
    May 18, 2015
    Posts:
    2
    I am trying to make a first person thing where you use the W and S keys to move and the A D keys to turn the camera. I am using a sphere to hold the camera's position. I have locked the X and Z rotations. I tried something, but I know it doesn't work. Please help me fix this code and explain what I did wrong in detail. I am very new to Unity.

    using UnityEngine;
    using System.Collections;

    public class PlayerMovement : MonoBehaviour
    {
    public float moveSpeed, lookSpeed;

    private Rigidbody rb;

    void Start()
    {
    rb = GetComponent<Rigidbody>();
    }

    void FixedUpdate()
    {
    float move = Input.GetAxis ("Verticle");
    float look = Input.GetAxis ("Horizontal");

    Vector3 movement = new Vector3(move,0.0f,0.0f);
    Vector3 looking = new Vector3 (0.0f,look,0.0f);

    transform.Rotate (moveSpeed * look);
    rb.AddForce (movement * speed);
    }
    }

    If I need to be more specific about my problem, please ask for more detail.

    Also, is it perhaps a little too early of me to try and do this?
     
  2. parandham03

    parandham03

    Joined:
    May 2, 2012
    Posts:
    174
    what problem u are facing in above code?
     
  3. Nitugard

    Nitugard

    Joined:
    May 10, 2015
    Posts:
    341
  4. Nitugard

    Nitugard

    Joined:
    May 10, 2015
    Posts:
    341
    You have one typo in your script:

    Code (CSharp):
    1. float move = Input.GetAxis ("Verticle");
    replace with:

    Code (CSharp):
    1. float move = Input.GetAxis ("Vertical");
    Hope it solved your issue!
     
  5. pebble225

    pebble225

    Joined:
    May 18, 2015
    Posts:
    2
    We will see. And as a response toparandham. I am trying to use a sphere to hold the camera in a scene of mine. I am trying to make the ball move in certain ways so that it is somewhat like a first person lookaraound.