- Home /
Question by
JustACode · Dec 31, 2020 at 12:50 AM ·
movement scriptglitching
Hello I am trying to fix my movePoint in my player grid movement script. When my game starts it get offset by 0.19 and when the y-axis go positive it randomly adds 0.1. How do I fix that?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControllerScript : MonoBehaviour
{
public float moveSpeed = 5f;
public Transform movePoint;
public LayerMask colliderLayer;
// 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);
//Checks if movePoint and player are together to make the movement
if (Vector3.Distance(transform.position, movePoint.position) <= .05f)
{
// Left and Right Movement
if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) == 1f)
{
// Checks for colliders
if (!Physics2D.OverlapCircle(movePoint.position + new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f), 0.2f, colliderLayer))
{
movePoint.position += new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f);
}
}
// Up and Down Movement
else if (Mathf.Abs(Input.GetAxisRaw("Vertical")) == 1f)
{
// Checks for colliders
if (!Physics2D.OverlapCircle(movePoint.position + new Vector3(0f, I Input.GetAxisRaw("Vertical"), 0f), 0.2f, colliderLayer))
{
movePoint.position += new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f);
}
}
}
}
}
Comment
Best Answer
Answer by JustACode · Jan 01, 2021 at 12:50 AM
Tries to fix it don't work, delete it then undo works, why?
Your answer
Follow this Question
Related Questions
How to make a rigidbody move in the direction of finger(x,y,z) 1 Answer
How to stop jittering with movement script 1 Answer
Trying to fix my movement after the camera broke it. 0 Answers
How to make a 3rd person character controller 0 Answers
New to Unity & Scripting, How Do I Create a Movement System Thats About Building Up Speed? 0 Answers