added a very basic boat simulation
This commit is contained in:
37
resources/scenes/Player.gd
Normal file
37
resources/scenes/Player.gd
Normal file
@@ -0,0 +1,37 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
const WIND = 20
|
||||
const SPEED = 400
|
||||
const STEERING = deg2rad(5)
|
||||
const WINDLIMIT = deg2rad(180-45)
|
||||
const WINDDIR = Vector2(0,1)
|
||||
const STEERPEN = 1
|
||||
const ACCELERATION = 2
|
||||
|
||||
var velocity = Vector2(0,10)
|
||||
|
||||
func _calculate_velocity(_velocity, _acceleration, _rotation):
|
||||
velocity = _velocity * _acceleration
|
||||
velocity = velocity.clamped(_calculate_maxspeed())
|
||||
return velocity.rotated(_rotation)
|
||||
|
||||
func _calculate_maxspeed():
|
||||
var angle_to_wind = WINDDIR.angle_to(velocity)
|
||||
if angle_to_wind > WINDLIMIT || angle_to_wind < -WINDLIMIT:
|
||||
return 0.1
|
||||
else:
|
||||
return 75
|
||||
|
||||
func _physics_process(_delta):
|
||||
if Input.is_action_pressed("right"):
|
||||
velocity = _calculate_velocity(velocity, STEERPEN, STEERING)
|
||||
rotate(STEERING)
|
||||
elif Input.is_action_pressed("left"):
|
||||
velocity = _calculate_velocity(velocity, STEERPEN, -STEERING)
|
||||
rotate(-STEERING)
|
||||
else:
|
||||
velocity = _calculate_velocity(velocity, ACCELERATION, 0)
|
||||
velocity = move_and_slide(velocity)
|
||||
|
||||
func _ready():
|
||||
pass
|
Reference in New Issue
Block a user