MrDucky38
MrDucky38

Reputation: 23

Unity3D Player Movement

I am trying to do my player movement script in C# and for some reason, when I launch the game in unity it still doesn't work. I was wondering if after setting up the vectors in the script, if I need to say what button can be pressed to make the player move.

Here's my code that I have. (can't Post Pictures Currently)

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
{
    public float speed;
    public Rigidbody rb;

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

    void fixedupdate()
    {
        float movementHorizontal = Input.GetAxis ("Horizontal");
        float movementVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (movementHorizontal, 0.0f, movementVertical);

        rb.AddForce (movement * speed);
    }
}

Upvotes: 0

Views: 1679

Answers (2)

Soviut
Soviut

Reputation: 91615

You have named your methods incorrectly; The case matters. Because of this, they never get called. Instead they should be:

void Start()

and

void FixedUpdate()

Unity doesn't throw any errors because it thinks what you've written are your own private methods.

Upvotes: 3

Keiwan
Keiwan

Reputation: 8301

C# is case sensitive so if this is your exact code your functions will never be called. They need to be called Start() and FixedUpdate()

Upvotes: 4

Related Questions