Skip to content

Commit

Permalink
Tilt the bird based on the player direction
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgraham committed Jan 31, 2022
1 parent 57f2874 commit 7c6bb19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions Assets/Scenes/Flappy Bird.unity
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ MonoBehaviour:
- {fileID: 21300000, guid: 477a76ff29832b2499b9244de7070326, type: 3}
strength: 5
gravity: -9.81
tilt: 5
--- !u!1 &892178073
GameObject:
m_ObjectHideFlags: 0
Expand Down
9 changes: 8 additions & 1 deletion Assets/Scripts/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class Player : MonoBehaviour

public float strength = 5f;
public float gravity = -9.81f;
public float tilt = 5f;

private Vector3 direction;

private void Awake()
Expand All @@ -25,7 +27,6 @@ private void OnEnable()
Vector3 position = transform.position;
position.y = 0f;
transform.position = position;

direction = Vector3.zero;
}

Expand All @@ -35,8 +36,14 @@ private void Update()
direction = Vector3.up * strength;
}

// Apply gravity and update the position
direction.y += gravity * Time.deltaTime;
transform.position += direction * Time.deltaTime;

// Tilt the bird based on the direction
Vector3 rotation = transform.eulerAngles;
rotation.z = direction.y * tilt;
transform.eulerAngles = rotation;
}

private void AnimateSprite()
Expand Down

0 comments on commit 7c6bb19

Please sign in to comment.