Hello everybody. I’m new to the community and I’m new to C#, i got a problem.
I’m trying to write down a script able to make my player walks on a grid.
I saw the gridMove on the Unify Wiki but it’s not what I’m looking for, so I’m trying by myself.
Here what I’ve been doing:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
private float MoveSpeed = 1.2f;
private float GridSize = 18f;
// Update is called once per frame
void Update () {
//Player Rotation
if (Input.GetKeyDown (KeyCode.UpArrow)) {
transform.forward = new Vector3 (0,0,-1);
}
else if (Input.GetKeyDown (KeyCode.DownArrow)) {
transform.forward = new Vector3 (0,0,1);
}
else if (Input.GetKeyDown (KeyCode.RightArrow)) {
transform.forward = new Vector3 (-1,0,0);
}
else if (Input.GetKeyDown (KeyCode.LeftArrow)) {
transform.forward = new Vector3 (1,0,0);
}
//Player translation
if (Input.GetKey (KeyCode.UpArrow)) {
transform.Translate (Vector3.back *GridSize, Space.Self);
}
else if (Input.GetKey (KeyCode.DownArrow)) {
transform.Translate (Vector3.back * GridSize, Space.Self);
}
else if (Input.GetKey (KeyCode.LeftArrow)) {
transform.Translate (Vector3.back * GridSize, Space.Self);
}
else if (Input.GetKey (KeyCode.RightArrow)) {
transform.Translate (Vector3.back * GridSize, Space.Self);
}
}
The player moves perfectly on the grid wich size is 18, but it does with an elevate speed.
I setted a MoveSpeed value, but i don’t know how to use it in the script to regulate the player movements. As I said before, I’m new to C#, can someone Help me?
The game I’m working on it’s a Pokèmon FanGame with a 3D style, similiar to the last ones from Game Freak.