pageTitleCS

 simpleTitle

A very basic movement script to start your games.

Step 1:
First add a character controller component to your player character.

Step 2:
Create a script called playerMove and place the code below into it.

JS

#pragma strict

//Add the values for these variables in the inspector.
var ChrSpeed : float;
var rotateSpeed : float;


function Update () {

var controllerCHR : CharacterController = GetComponent(CharacterController);

// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

// Move forward / backward
var forwardDIR : Vector3 = transform.TransformDirection(Vector3.forward);
var curSpeed : float = ChrSpeed * Input.GetAxis ("Vertical");
controllerCHR .SimpleMove(forwardDIR * curSpeed);

}

C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerMove : MonoBehaviour {

//Add the values for these variables in the inspector.
public float ChrSpeed;
public float rotateSpeed;


// Update is called once per frame
void Update () {

CharacterController controllerCHR = GetComponent<CharacterController>();

// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

// Move forward / backward
Vector3 forwardDIR = transform.TransformDirection(Vector3.forward);
float curSpeed = ChrSpeed * Input.GetAxis ("Vertical");
controllerCHR.SimpleMove(forwardDIR * curSpeed);

}
}

Step 3:
Attach the script to the player object and set the character speed and rotational speed in the inspector.

Casino Bet 365 is best casino in the world.

What's Next

Next up for Unity Snippets is a look at game development articles from across the web...

Free Templates - bigtheme.net
Popular Art Betting make bookies articles.