Skip to content

Commit

Permalink
Fixes issues #90, #76, #93. Player walk animation direction now is di…
Browse files Browse the repository at this point in the history
…rectly linked to internal movement vector.
  • Loading branch information
Streus committed Apr 5, 2018
1 parent 29fef68 commit 612ee98
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions Assets/Scripts/Actor/Control/Controllers/Player.cs
Expand Up @@ -250,44 +250,29 @@ public void move()
if (PlayerControlManager.GetKey(ControlInput.UP)) // UP
{
movementVector += Vector2.up;
anim.SetInteger ("Direction", 2);
// if(!GlobalAudio.ClipIsPlaying(AudioLibrary.inst.playerWalking))
// {
// AudioLibrary.PlayerWalking();
// anim.SetInteger ("Direction", 2);
// }
}
if (PlayerControlManager.GetKey(ControlInput.LEFT)) // LEFT
{
movementVector += Vector2.left;
anim.SetInteger ("Direction", 3);
// if (!GlobalAudio.ClipIsPlaying(AudioLibrary.inst.playerWalking))
// {
// AudioLibrary.PlayerWalking();
// anim.SetInteger ("Direction", 3);
// }
}
if (PlayerControlManager.GetKey(ControlInput.DOWN)) // DOWN
{
movementVector += Vector2.down;
anim.SetInteger ("Direction", 4);
// if (!GlobalAudio.ClipIsPlaying(AudioLibrary.inst.playerWalking))
// {
// AudioLibrary.PlayerWalking();
// anim.SetInteger ("Direction", 4);
// }
}
if (PlayerControlManager.GetKey(ControlInput.RIGHT)) // RIGHT
{
movementVector += Vector2.right;
anim.SetInteger ("Direction", 1);
// if (!GlobalAudio.ClipIsPlaying(AudioLibrary.inst.playerWalking))
// {
// AudioLibrary.PlayerWalking();
// anim.SetInteger ("Direction", 1);
// }
}

//update animator on movement direction, if we're moving
if(movementVector != Vector2.zero)
{
float zRot = Vector2.SignedAngle (Vector2.right, movementVector);
zRot += zRot < 0f ? 360f : 0f;
int quadrant = (int)((zRot / 360f) * 4f);
anim.SetInteger ("Direction", quadrant + 1);
}

movementVector = movementVector.normalized * getSelf().getMovespeed() * Time.deltaTime;
physbody.velocity += movementVector;
if (physbody.velocity.magnitude > getSelf ().getMovespeed ())
Expand All @@ -312,11 +297,6 @@ public void move()
platformFilter.SetLayerMask(1 << LayerMask.NameToLayer("SkyEnts"));
platformFilter.useTriggers = true;

//pitCount = GetComponent<Collider2D>().Cast(movementVector, pitFilter, pitsFound, getSelf().getMovespeed() * Time.deltaTime * 1.2f);


//platformCount = GetComponent<Collider2D>().Cast(movementVector, platformFilter, platformsFound, getSelf().getMovespeed() * Time.deltaTime * 1.2f);

Vector2 colSize = gameObject.GetComponent<BoxCollider2D> ().size;
Vector2 moveVect = new Vector2(movementVector.normalized.x * colSize.x * 0.5f, movementVector.normalized.y * colSize.y);
platformCount = Physics2D.OverlapBox((Vector3)GetComponent<Collider2D>().offset + transform.position + (Vector3)(moveVect), GetComponent<BoxCollider2D>().size, 0, platformFilter, platformsFound);
Expand Down

0 comments on commit 612ee98

Please sign in to comment.