My sprite looks like it is haveing a seizure. What am I doing wrong?
Trying to create a 2d Top down random movement. I have the blendtree setup so that it faces the sprite in the right direction. However, I can't get it move right. It just flips back and forth between directions never moving. Unless I use the RidgidBody2d apply force then it just slowly convulses to 0,0.
I guess I wanted it walk in one direction base cardinal direction (no angles) for 3 seconds then change direction.
What Am I doing wrong?
public float moveSpeed = 0.75f;
public Animator anim;
public Rigidbody2D body;
private Vector2 enemyMovement;
void Start () {
anim = GetComponent<Animator> ();
}
void Update () {
Invoke("randomDirection", 1);
transform.position = new Vector3(enemyMovement.x,enemyMovement.y,0) * moveSpeed * Time.deltaTime;
//TRIED THIS TOO
//body.AddForce (enemyMovement);
}
void randomDirection() {
switch(Random.Range (0,3)){
case 0:
Debug.Log ("Moving enemy Up");
enemyMovement = new Vector2 (0,1);
break;
case 1:
Debug.Log ("Moving enemy Right");
enemyMovement = new Vector2 (1,0);
break;
case 2:
Debug.Log ("Moving enemy Down");
enemyMovement = new Vector2 (0,-1);
break;
case 3:
Debug.Log ("Moving enemy Left");
enemyMovement = new Vector2 (-1,0);
break;
default:
enemyMovement = new Vector2 (0,0);
break;
}
anim.SetBool ("Walking", true);
DefineFacingDirection (enemyMovement);
}
Answer by PapaGrinki · Aug 18, 2016 at 03:25 PM
I'm making a 3D project, but the same thing happend to me. Anyway, I fixed it by detaching the camera from the physical body. Hard to explain, but I have an empty object, and below it all of the shapes I needed. I tried putting the camera below all of that, but it ended up in a seizure. So I put the camera below the empty object instead and not the shapes. I'll just put in a picture.
It fixed the problem, but it dosen't follow the character. It fixed it for me, but I have no idea if it will work for you.