1-
21extends KinematicBody2D
32
4- # This is a simple collision demo showing how
5- # the kinematic controller works.
6- # move() will allow to move the node, and will
7- # always move it to a non-colliding spot,
8- # as long as it starts from a non-colliding spot too.
3+ # This demo shows how to build a kinematic controller.
94
105# Member variables
11- const GRAVITY = 500.0 # Pixels /second
6+ const GRAVITY = 500.0 # pixels/second /second
127
138# Angle in degrees towards either side that the player can consider "floor"
149const FLOOR_ANGLE_TOLERANCE = 40
@@ -19,8 +14,8 @@ const STOP_FORCE = 1300
1914const JUMP_SPEED = 200
2015const JUMP_MAX_AIRBORNE_TIME = 0.2
2116
22- const SLIDE_STOP_VELOCITY = 1.0 # One pixel per second
23- const SLIDE_STOP_MIN_TRAVEL = 1.0 # One pixel
17+ const SLIDE_STOP_VELOCITY = 1.0 # one pixel/ second
18+ const SLIDE_STOP_MIN_TRAVEL = 1.0 # one pixel
2419
2520var velocity = Vector2 ()
2621var on_air_time = 100
@@ -39,38 +34,38 @@ func _physics_process(delta):
3934
4035 var stop = true
4136
42- if ( walk_left ) :
43- if ( velocity .x <= WALK_MIN_SPEED and velocity .x > - WALK_MAX_SPEED ) :
37+ if walk_left :
38+ if velocity .x <= WALK_MIN_SPEED and velocity .x > - WALK_MAX_SPEED :
4439 force .x -= WALK_FORCE
4540 stop = false
46- elif ( walk_right ) :
47- if ( velocity .x >= - WALK_MIN_SPEED and velocity .x < WALK_MAX_SPEED ) :
41+ elif walk_right :
42+ if velocity .x >= - WALK_MIN_SPEED and velocity .x < WALK_MAX_SPEED :
4843 force .x += WALK_FORCE
4944 stop = false
5045
51- if ( stop ) :
46+ if stop :
5247 var vsign = sign (velocity .x )
5348 var vlen = abs (velocity .x )
5449
55- vlen -= STOP_FORCE * delta
56- if ( vlen < 0 ) :
50+ vlen -= STOP_FORCE * delta
51+ if vlen < 0 :
5752 vlen = 0
5853
59- velocity .x = vlen * vsign
54+ velocity .x = vlen * vsign
6055
6156 # Integrate forces to velocity
62- velocity += force * delta
57+ velocity += force * delta
6358 # Integrate velocity into motion and move
64- velocity = move_and_slide (velocity ,Vector2 (0 ,- 1 ))
59+ velocity = move_and_slide (velocity , Vector2 (0 , - 1 ))
6560
66- if ( is_on_floor () ):
67- on_air_time = 0
61+ if is_on_floor ():
62+ on_air_time = 0
6863
69- if ( jumping and velocity .y > 0 ) :
64+ if jumping and velocity .y > 0 :
7065 # If falling, no longer jumping
7166 jumping = false
7267
73- if ( on_air_time < JUMP_MAX_AIRBORNE_TIME and jump and not prev_jump_pressed and not jumping ) :
68+ if on_air_time < JUMP_MAX_AIRBORNE_TIME and jump and not prev_jump_pressed and not jumping :
7469 # Jump must also be allowed to happen if the character left the floor a little bit ago.
7570 # Makes controls more snappy.
7671 velocity .y = - JUMP_SPEED
0 commit comments