summaryrefslogtreecommitdiff
path: root/demos/2d/kinematic_char
diff options
context:
space:
mode:
authorJuan Linietsky <red@kyoko>2015-05-11 15:49:41 -0300
committerJuan Linietsky <red@kyoko>2015-05-11 15:49:41 -0300
commit4b8745ad63409cf14b02735981ee35d2f794421c (patch)
tree607dcfbb77430e8ed7eef25de6b7bec9c4032aec /demos/2d/kinematic_char
parentdda60296d81edaabfdb56f47a2c949b5dad283fb (diff)
parentb777bf5ff5c3891daa0f93987ca12d0d7d053c2b (diff)
Merge branch 'master' of https://github.com/okamstudio/godot
Diffstat (limited to 'demos/2d/kinematic_char')
-rw-r--r--demos/2d/kinematic_char/circle.pngbin0 -> 6107 bytes
-rw-r--r--demos/2d/kinematic_char/colworld.scnbin6596 -> 7459 bytes
-rw-r--r--demos/2d/kinematic_char/long_obstacle.pngbin0 -> 534 bytes
-rw-r--r--demos/2d/kinematic_char/player.gd40
4 files changed, 29 insertions, 11 deletions
diff --git a/demos/2d/kinematic_char/circle.png b/demos/2d/kinematic_char/circle.png
new file mode 100644
index 0000000000..ddb3ac4b9c
--- /dev/null
+++ b/demos/2d/kinematic_char/circle.png
Binary files differ
diff --git a/demos/2d/kinematic_char/colworld.scn b/demos/2d/kinematic_char/colworld.scn
index 6c73e8b126..e66705368d 100644
--- a/demos/2d/kinematic_char/colworld.scn
+++ b/demos/2d/kinematic_char/colworld.scn
Binary files differ
diff --git a/demos/2d/kinematic_char/long_obstacle.png b/demos/2d/kinematic_char/long_obstacle.png
new file mode 100644
index 0000000000..88cb22daee
--- /dev/null
+++ b/demos/2d/kinematic_char/long_obstacle.png
Binary files differ
diff --git a/demos/2d/kinematic_char/player.gd b/demos/2d/kinematic_char/player.gd
index e8b3cc8d00..329382408b 100644
--- a/demos/2d/kinematic_char/player.gd
+++ b/demos/2d/kinematic_char/player.gd
@@ -21,6 +21,9 @@ const STOP_FORCE = 1300
const JUMP_SPEED = 200
const JUMP_MAX_AIRBORNE_TIME=0.2
+const SLIDE_STOP_VELOCITY=1.0 #one pixel per second
+const SLIDE_STOP_MIN_TRAVEL=1.0 #one pixel
+
var velocity = Vector2()
var on_air_time=100
var jumping=false
@@ -31,8 +34,6 @@ func _fixed_process(delta):
#create forces
var force = Vector2(0,GRAVITY)
-
- var stop = velocity.x!=0.0
var walk_left = Input.is_action_pressed("move_left")
var walk_right = Input.is_action_pressed("move_right")
@@ -86,25 +87,42 @@ func _fixed_process(delta):
#char is on floor
on_air_time=0
floor_velocity=get_collider_velocity()
- #velocity.y=0
- #But we were moving and our motion was interrupted,
- #so try to complete the motion by "sliding"
- #by the normal
- motion = n.slide(motion)
- velocity = n.slide(velocity)
-
- #then move again
- move(motion)
+
+ if (on_air_time==0 and force.x==0 and get_travel().length() < SLIDE_STOP_MIN_TRAVEL and abs(velocity.x) < SLIDE_STOP_VELOCITY and get_collider_velocity()==Vector2()):
+ #Since this formula will always slide the character around,
+ #a special case must be considered to to stop it from moving
+ #if standing on an inclined floor. Conditions are:
+ # 1) Standing on floor (on_air_time==0)
+ # 2) Did not move more than one pixel (get_travel().length() < SLIDE_STOP_MIN_TRAVEL)
+ # 3) Not moving horizontally (abs(velocity.x) < SLIDE_STOP_VELOCITY)
+ # 4) Collider is not moving
+
+ revert_motion()
+ velocity.y=0.0
+
+ else:
+ #For every other case of motion,our motion was interrupted.
+ #Try to complete the motion by "sliding"
+ #by the normal
+
+ motion = n.slide(motion)
+ velocity = n.slide(velocity)
+ #then move again
+ move(motion)
if (floor_velocity!=Vector2()):
#if floor moves, move with floor
move(floor_velocity*delta)
if (jumping and velocity.y>0):
+ #if falling, no longer jumping
jumping=false
if (on_air_time<JUMP_MAX_AIRBORNE_TIME and jump and not prev_jump_pressed and not jumping):
+ # Jump must also be allowed to happen if the
+ # character left the floor a little bit ago.
+ # Makes controls more snappy.
velocity.y=-JUMP_SPEED
jumping=true