Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

Commit

Permalink
add an unfinished and disable sway animation
Browse files Browse the repository at this point in the history
  • Loading branch information
martindzejky committed Apr 25, 2021
1 parent ad5639d commit eeb683e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/treeConstants.tres
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ stabilityPerBranch = -1.0
stabilityPerRoot = 1.2
minGrowthLength = 4.0
maxGrowthLength = 15.0
maxGrowthAngle = 30.0
maxGrowthAngle = 40.0
maxBranchChildren = 2.0
minRotationDifference = 20.0
requiredEnergyForRootGrowth = 2.4
Expand Down
20 changes: 20 additions & 0 deletions scripts/branch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@ export(float) var thickness


var branchParents = 0
var originalRotation


func _enter_tree():
updateThickness()
updateBranchParents()

originalRotation = rotation_degrees


func _process(delta):
updatePosition()

# DISABLED because I did not have enough time to tweak this
# animation and it looked weird...
# animateSwayInWind()

# destroy the branch if it overlaps the ground
if $end.global_position.y * growDirection < 0:
if not has_node('placeholder'):
Expand All @@ -41,6 +48,19 @@ func isLeaf() -> bool:
return $children.get_child_count() == 0


func animateSwayInWind():
# only sway branches above ground
if growDirection >= 0:
return

var timeConstant = (OS.get_ticks_msec() as float) / 1000

# delay branches further up the tree
timeConstant -= branchParents * 1.5

rotation_degrees = originalRotation + 2 * sin(timeConstant)


func updatePosition():
# update the relative position of this branch based on the length
# of the parent
Expand Down

0 comments on commit eeb683e

Please sign in to comment.