I am having an issue on how to move sideways

My player cannot move sideways whenever I tick on the box. The following is my scripts:

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5.0f;
public float rotateSpeed = 60.0f;
public bool canMoveSideways = false;

void Update()
{
Movement();
}

void Movement()
{
if (Input.GetKey(KeyCode.UpArrow))
{
Debug.Log(“Key UpArrow Pressed.”);

this.transform.Translate (new Vector3(0, 0, moveSpeed * Time.deltaTime));
}
else if (Input.GetKey(KeyCode.DownArrow))
{
Debug.Log(“Key DownArrow Pressed.”);

this.transform.Translate (new Vector3(0, 0, -moveSpeed * Time.deltaTime));
}

if (Input.GetKey(KeyCode.LeftArrow))
{
if (canMoveSideways)
{
Debug.Log(“Key LeftArrow Pressed.”);

this.transform.Translate (new Vector3(-moveSpeed * Time.deltaTime, 0, 0));
}
else
{
Debug.Log(“Key LeftArrow Pressed:Rotate”);

this.transform.Rotate (new Vector3(0, -rotateSpeed * Time.deltaTime, 0));
}
}
else if (Input.GetKey(KeyCode.RightArrow))
{
if (canMoveSideways)
{
Debug.Log(“Key RightArrow Pressed.”);

this.transform.Translate (new Vector3(moveSpeed * Time.deltaTime, 0, 0));
}
else
{
Debug.Log(“Key RightArrow Pressed:Rotate”);

this.transform.Rotate (new Vector3(0, rotateSpeed * Time.deltaTime, 0));
}
}

if (Input.GetKey(KeyCode.W))
{
Debug.Log(“Key W Pressed.”);

this.transform.Translate (new Vector3(0, moveSpeed * Time.deltaTime, 0));
}
else if (Input.GetKey(KeyCode.S))
{
Debug.Log(“Key S Pressed.”);

this.transform.Translate (new Vector3(0, -moveSpeed * Time.deltaTime, 0));
}
}
}

Welcome to the forums! To get a good answer to a question like this, please do two things: (1) use code tags (in the formatting toolbar), and (2) don’t just say “I can’t do it” or “it doesn’t work”… instead describe exactly what happens when you try, and how this differs from what you expected.

5 Likes

3; try to find the proper topic to ask questions, coding questions aren’t good in the game design topic

4 Likes

You should say what is happening, like if your Debug.Log messages you are using are outputing or not, and if the Debug.Log messages indicate the character should be sliding or rotating. As it is, I’m wondering if you are setting canMoveSideways back to false in some other script.

3 Likes