diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-12-09 09:10:00 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-12-09 09:10:00 -0300 |
commit | aadced2f72476f637c6c14e48d3811e088eda951 (patch) | |
tree | 34df51f29d92225f28dcdfc495b8796ae7430ceb /demos/3d/kinematic_char | |
parent | 6bc6b8fcf24bdfcae4a990054c9077e1bc5a87e5 (diff) | |
parent | db9da152765357c5e484792fc5e31a25acbc7616 (diff) |
Merge branch 'master' of https://github.com/godotengine/godot
Diffstat (limited to 'demos/3d/kinematic_char')
-rw-r--r-- | demos/3d/kinematic_char/cubio.gd | 91 | ||||
-rw-r--r-- | demos/3d/kinematic_char/follow_camera.gd | 62 | ||||
-rw-r--r-- | demos/3d/kinematic_char/level.scn | bin | 15523 -> 18847 bytes | |||
-rw-r--r-- | demos/3d/kinematic_char/purplecube.scn | bin | 9808 -> 7927 bytes |
4 files changed, 66 insertions, 87 deletions
diff --git a/demos/3d/kinematic_char/cubio.gd b/demos/3d/kinematic_char/cubio.gd index 058b919d05..769ada3bca 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,77 @@ const ACCEL= 2 const DEACCEL= 4 const MAX_SLOPE_ANGLE = 30 -func _fixed_process(delta): - var dir = Vector3() #where does the player intend to walk to +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 attempts=4 + 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 diff --git a/demos/3d/kinematic_char/follow_camera.gd b/demos/3d/kinematic_char/follow_camera.gd index cf7172d7bb..37a1402053 100644 --- a/demos/3d/kinematic_char/follow_camera.gd +++ b/demos/3d/kinematic_char/follow_camera.gd @@ -1,69 +1,57 @@ extends Camera -# member variables here, example: -# var a=2 -# var b="textvar" - -var collision_exception=[] -export var min_distance=0.5 -export var max_distance=4.0 -export var angle_v_adjust=0.0 -export var autoturn_ray_aperture=25 -export var autoturn_speed=50 +# Member variables +var collision_exception = [] +export var min_distance = 0.5 +export var max_distance = 4.0 +export var angle_v_adjust = 0.0 +export var autoturn_ray_aperture = 25 +export var autoturn_speed = 50 var max_height = 2.0 var min_height = 0 + func _fixed_process(dt): - var target = get_parent().get_global_transform().origin + var target = get_parent().get_global_transform().origin var pos = get_global_transform().origin - var up = Vector3(0,1,0) + var up = Vector3(0, 1, 0) var delta = pos - target - #regular delta follow + # Regular delta follow - #check ranges - + # Check ranges if (delta.length() < min_distance): - delta = delta.normalized() * min_distance + delta = delta.normalized()*min_distance elif (delta.length() > max_distance): - delta = delta.normalized() * max_distance + delta = delta.normalized()*max_distance - #check upper and lower height - if ( delta.y > max_height): + # Check upper and lower height + if (delta.y > max_height): delta.y = max_height - if ( delta.y < min_height): + if (delta.y < min_height): delta.y = min_height - + pos = target + delta - look_at_from_pos(pos,target,up) + look_at_from_pos(pos, target, up) - #turn a little up or down + # Turn a little up or down var t = get_transform() - t.basis = Matrix3(t.basis[0],deg2rad(angle_v_adjust)) * t.basis + t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis set_transform(t) - - -func _ready(): -#find collision exceptions for ray +func _ready(): + # Find collision exceptions for ray var node = self while(node): if (node extends RigidBody): collision_exception.append(node.get_rid()) break else: - node=node.get_parent() - # Initalization here + node = node.get_parent() set_fixed_process(true) - #this detaches the camera transform from the parent spatial node + # This detaches the camera transform from the parent spatial node set_as_toplevel(true) - - - - - - diff --git a/demos/3d/kinematic_char/level.scn b/demos/3d/kinematic_char/level.scn Binary files differindex 8be64c61c0..0082f55f43 100644 --- a/demos/3d/kinematic_char/level.scn +++ b/demos/3d/kinematic_char/level.scn diff --git a/demos/3d/kinematic_char/purplecube.scn b/demos/3d/kinematic_char/purplecube.scn Binary files differindex ab758366fd..e3ed1bf84b 100644 --- a/demos/3d/kinematic_char/purplecube.scn +++ b/demos/3d/kinematic_char/purplecube.scn |