Last active
November 3, 2020 22:01
-
-
Save hfabre/fd6994c9ad3160eac17fe138b667049f to your computer and use it in GitHub Desktop.
Grappling hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def center_x | |
@x / 2 | |
end | |
def center_y | |
@y / 2 | |
end | |
def normalize(x, y) | |
magn = Math.sqrt(x*x + y*y) | |
[x / magn, y / magn] | |
end | |
swing_x = @x - @hook.x | |
swing_y = @y - @hook.y | |
norm = normalize(swing_x, swing_y) | |
# Step 1 | |
@x = Math.cos(@hook_angular_velocity) * (self.center_x - @hook.center_x) - Math.sin(@hook_angular_velocity) * (self.center_y - @hook.center_y) + @hook.center_x | |
@y = Math.sin(@hook_angular_velocity) * (self.center_x - @hook.center_x) + Math.cos(@hook_angular_velocity) * (self.center_y - @hook.center_y) + @hook.center_y | |
# Step 2 | |
# @x = Math.cos(@hook_angular_velocity + norm.first) * (@x - @hook.x) - Math.sin(@hook_angular_velocity + norm.first) * (@y - @hook.y) + @hook.x | |
# @y = Math.sin(@hook_angular_velocity + norm.first) * (@x - @hook.x) + Math.cos(@hook_angular_velocity + norm.first) * (@y - @hook.y) + @hook.y | |
# Step 3 | |
# @x = Math.cos(@hook_angular_velocity * @friction + norm.first) * (@x - @hook.x) - Math.sin(@hook_angular_velocity * @friction + norm.first) * (@y - @hook.y) + @hook.x | |
# @y = Math.sin(@hook_angular_velocity * @friction + norm.first) * (@x - @hook.x) + Math.cos(@hook_angular_velocity * @friction + norm.first) * (@y - @hook.y) + @hook.y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment