So during gameplay, my simple slime enemy is moving very slow and he won’t glide across the world smoothly, he’s just going from one square, then teleporting to another. I have it set so that he can stop and choose a different direction, but he seems to be only changing on the Y axis (i can figure that out later). Here’s the code I’ve used for my slime guy below. (Yes i know theres extra code that will go in later choosing a random countdown and stuff like that) i really just want to know why he won’t move smoothly, bc I’m starting to think is just something to do with unity on my mac. Any help would be great tho:) thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class slimeController : MonoBehaviour {
public float moveSpeed;
private Rigidbody2D slimeRigidbody;
private bool moving;
public float timeBetweenMove;
private float timeBetweenMoveCounter;
public float timeToMove;
private float timeToMoveCounter;
private Vector3 moveDirection;
// Use this for initialization
void Start () {
timeBetweenMoveCounter = timeBetweenMove;
timeToMoveCounter = timeToMove;
slimeRigidbody = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
if (moving) {
timeToMoveCounter -= Time.deltaTime;
slimeRigidbody.velocity = moveDirection;
if (timeBetweenMoveCounter < 0f) {
moving = false;
timeBetweenMoveCounter = timeBetweenMove;
}
} else {
timeBetweenMoveCounter -= Time.deltaTime;
slimeRigidbody.velocity = Vector2.zero;
if (timeBetweenMoveCounter < 0f) {
moving = true;
timeToMoveCounter = timeToMove;
moveDirection = new Vector3 (Random.Range (-1f, 1f) * moveSpeed, Random.Range (-1f, 1f) * moveSpeed, 0f);
}
}
}
}