I am brand new and trying to make a game for class. The idea is the player will move left and right and objects will come at him (towards the screen) while it dodges.
Right now I have a sphere attached to a capsule as my player. The sphere and capsule are children of a “player” object located in the head, and the move script is in that object. When it moves left and right it doesn’t stay 100% vertical and if I hit the walls it tips over. I don’t want that. I want it to stay standing straight up the whole time.
Please help, My code is below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
this.transform.Translate(Vector3.left * Time.deltaTime * 10);
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
this.transform.Translate(Vector3.right * Time.deltaTime * 10);
}
}
}