summaryrefslogtreecommitdiff
path: root/demos/3d/kinematic_char/cubio.gd
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2015-12-09 08:38:23 +0100
committerRémi Verschelde <rverschelde@gmail.com>2015-12-09 08:38:23 +0100
commit8639cecf4cedd56452b47503be19c44b304cd02f (patch)
treee2a795da15e40c7d9d5b82e33378f8dbf0eaf67a /demos/3d/kinematic_char/cubio.gd
parentefbb834936fdc9da9789ad37c9cc61e0b90cda95 (diff)
Improve code formatting and update to 2.0
The scripts were streamlined using more or less the following conventions: - space after a comma in lists of arguments - space around weak operators (+, -), no space around strong operators (*, /) - space after a comment start (#) - removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now) - function blocks separate by two newlines The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
Diffstat (limited to 'demos/3d/kinematic_char/cubio.gd')
-rw-r--r--demos/3d/kinematic_char/cubio.gd86
1 files changed, 39 insertions, 47 deletions
diff --git a/demos/3d/kinematic_char/cubio.gd b/demos/3d/kinematic_char/cubio.gd
index 058b919d05..d2bd00bd0f 100644
--- a/demos/3d/kinematic_char/cubio.gd
+++ b/demos/3d/kinematic_char/cubio.gd
@@ -1,10 +1,7 @@
extends KinematicBody
-# member variables here, example:
-# var a=2
-# var b="textvar"
-
+# member variables
var g = -9.8
var vel = Vector3()
const MAX_SPEED = 5
@@ -13,83 +10,78 @@ const ACCEL= 2
const DEACCEL= 4
const MAX_SLOPE_ANGLE = 30
-func _fixed_process(delta):
+func _fixed_process(delta):
var dir = Vector3() #where does the player intend to walk to
var cam_xform = get_node("target/camera").get_global_transform()
if (Input.is_action_pressed("move_forward")):
- dir+=-cam_xform.basis[2]
+ dir += -cam_xform.basis[2]
if (Input.is_action_pressed("move_backwards")):
- dir+=cam_xform.basis[2]
+ dir += cam_xform.basis[2]
if (Input.is_action_pressed("move_left")):
- dir+=-cam_xform.basis[0]
+ dir += -cam_xform.basis[0]
if (Input.is_action_pressed("move_right")):
- dir+=cam_xform.basis[0]
-
- dir.y=0
- dir=dir.normalized()
-
- vel.y+=delta*g
+ dir += cam_xform.basis[0]
+
+ dir.y = 0
+ dir = dir.normalized()
+
+ vel.y += delta*g
var hvel = vel
- hvel.y=0
+ hvel.y = 0
var target = dir*MAX_SPEED
var accel
- if (dir.dot(hvel) >0):
- accel=ACCEL
+ if (dir.dot(hvel) > 0):
+ accel = ACCEL
else:
- accel=DEACCEL
-
- hvel = hvel.linear_interpolate(target,accel*delta)
+ accel = DEACCEL
+
+ hvel = hvel.linear_interpolate(target, accel*delta)
+
+ vel.x = hvel.x
+ vel.z = hvel.z
- vel.x=hvel.x;
- vel.z=hvel.z
-
var motion = move(vel*delta)
-
+
var on_floor = false
var original_vel = vel
-
-
- var floor_velocity=Vector3()
-
+ var floor_velocity = Vector3()
var attempts=4
while(is_colliding() and attempts):
- var n=get_collision_normal()
-
- if ( rad2deg(acos(n.dot( Vector3(0,1,0)))) < MAX_SLOPE_ANGLE ):
- #if angle to the "up" vectors is < angle tolerance
- #char is on floor
- floor_velocity=get_collider_velocity()
- on_floor=true
+ var n = get_collision_normal()
+
+ if (rad2deg(acos(n.dot(Vector3(0, 1, 0)))) < MAX_SLOPE_ANGLE):
+ # if angle to the "up" vectors is < angle tolerance
+ # char is on floor
+ floor_velocity = get_collider_velocity()
+ on_floor = true
motion = n.slide(motion)
vel = n.slide(vel)
if (original_vel.dot(vel) > 0):
- #do not allow to slide towads the opposite direction we were coming from
+ # do not allow to slide towads the opposite direction we were coming from
motion=move(motion)
- if (motion.length()<0.001):
+ if (motion.length() < 0.001):
break
- attempts-=1
-
- if (on_floor and floor_velocity!=Vector3()):
- move(floor_velocity*delta)
+ attempts -= 1
+
+ if (on_floor and floor_velocity != Vector3()):
+ move(floor_velocity*delta)
if (on_floor and Input.is_action_pressed("jump")):
- vel.y=JUMP_SPEED
-
+ vel.y = JUMP_SPEED
+
var crid = get_node("../elevator1").get_rid()
-# print(crid," : ",PS.body_get_state(crid,PS.BODY_STATE_TRANSFORM))
+
func _ready():
# Initalization here
set_fixed_process(true)
- pass
-func _on_tcube_body_enter( body ):
+func _on_tcube_body_enter(body):
get_node("../ty").show()
- pass # replace with function body