CORRIT
1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public Transform movePoint;
public LayerMask WhatStopsMovement;
// Start is called before the first frame update
void Start()
{
movePoint.parent = null;
}
// Update is called once per frame
void Update()
{
{
transform.position = Vector3.MoveTowards(transform.position, movePoint.position, moveSpeed * Time.deltaTime);
if (Vector3.Distance(transform.position, movePoint.position) <= .0005f)
{
if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) == 1f)
{
if(!Physics2D.OverlapCircle(movePoint.position + new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f), .2f, WhatStopsMovement))
{
movePoint.position += new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f);
}
}
if (Mathf.Abs(Input.GetAxisRaw("Vertical")) == 1f)
{
if (!Physics2D.OverlapCircle(movePoint.position + new Vector3(Input.GetAxisRaw("Vertical"), 0f, 0f), .2f, WhatStopsMovement))
{
movePoint.position += new Vector3(Input.GetAxisRaw("Vertical"), 0f, 0f);
}
}
}
}
}
}
movePoint.position += new Vector3(Input.GetAxisRaw(“Horizontal”), 0f, 0f); VS movePoint.position += new Vector3(Input.GetAxisRaw(“Vertical”), 0f, 0f); As you might notice, you are setting the x value of the vector3 on both cases. So you move in the x direction when using up/down and when using left/right. If you want to move forward on the z-axis, you need to assign the vertical input to the z-component of the vector3 and not the x component.