Script movement and jumping bug

Hello can someone help me ? i’m new to Unity and my script doesn’t work, the capsule doesn’t move when i use arrowKeys or spacebar.

Here is my script if someone could help me :frowning:

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
	
	CharacterController controller;
	[SerializeField]
	float movementSpeed = 10;
	[SerializeField]
	float jumpSpeed = 20.0f;
	[SerializeField]
	float yVelocity = 0;
	[SerializeField]
	float gravity = 1;
	
	
	// Use this for initialization
	void Start () {
		controller = GetComponent<CharacterController>();
	}
	
	// Update is called once per frame
	void Update () {
		Vector3 direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		Vector3 velocity = direction * movementSpeed;
		
		if(controller.isGrounded){
			
			if(Input.GetButtonDown("Jump")){
				
				yVelocity = jumpSpeed;
			}
			
			else{
				yVelocity -= gravity;
			}
			
			velocity.y = yVelocity;
			
			controller.Move(velocity*Time.deltaTime);
		}
	}
}

Right now you ony move the controller when its grounded and you also only apply gravity when its groumded. is that intentional?

Don’t know i took the code from a tutorial, i don’t even know what i’m doing i know java but i’m completely new to c# and Unity.

:frowning:

Do you think i should learn without a tutorial ?

Not, to get started its really better to use a tutorial to get used to unitys structures. When you are unsure why something in a tutorial is done its best to take a look at the unity script reference and maybe write down the explanation as comment so that you understand the complete script in the end.

Have you got any good 3rd person tutorial so far ?

The Walker Boys tutorials from a mouseclick- to a 3d platform-game are really good. They might be a bit slow if you already know how to program but you cna always skip forward.

Ok thanks a lot he uses Javascript, i should do it too ? i don’t know neither C# or javascript right now

I would rather use c#, its a real programming language and its syntax is pretty close to java. The code from the tutorials can be “translated” into c# pretty easily.

yes so first i learn c# and then i do the tutorials ?

If you already know the programming basics in only language you can just start off with the tutorials. When you are comfortable with unitys structures and feel like it you can continue the tutorials but write the code in c# instead of javascript/unityscript. Thats pretty easy because 99% of the unity functions are the same.

Will try it, thanks.

EDIT : So i do the 4 game training ?