Add ground collision

master
Fabien Freling 2018-07-19 15:37:08 +02:00
parent 7f5ed67a40
commit a0f3a249ab
4 changed files with 35 additions and 5 deletions

View File

@ -17,7 +17,7 @@ cell_scale = 1.0
collision_layer = 1
collision_mask = 1
data = {
"cells": PoolIntArray( 0, 0, 1441792, 65534, 0, 1441792, 65535, 0, 1441792, 0, 65534, 1441792, 65534, 65534, 1441792, 65535, 65534, 1441792, 0, 65535, 1441792, 65534, 65535, 1441792 )
"cells": PoolIntArray( 0, 0, 1612054528, 65534, 0, 1441792, 65535, 0, 1441792, 0, 65534, 1612054528, 65534, 65534, 1441792, 65535, 65534, 1441792, 0, 65535, 1441792, 65534, 65535, 1441792 )
}
_sections_unfolded = [ "Cell", "Collision", "Transform", "Visibility" ]
__meta__ = {

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[sub_resource type="CubeMesh" id=1]
@ -59,6 +59,10 @@ proximity_fade_enable = false
distance_fade_enable = false
_sections_unfolded = [ "Albedo" ]
[sub_resource type="BoxShape" id=6]
extents = Vector3( 1, 1, 1 )
[sub_resource type="CubeMesh" id=3]
size = Vector3( 2, 2, 2 )
@ -79,7 +83,7 @@ void fragment() {
render_priority = 0
shader = SubResource( 4 )
[node name="Spatial" type="Spatial"]
[node name="Spatial" type="Spatial" index="0"]
[node name="MeshSpatial" type="MeshInstance" parent="." index="0"]
@ -98,6 +102,23 @@ skeleton = NodePath("..")
material/0 = SubResource( 2 )
_sections_unfolded = [ "material" ]
[node name="StaticBody" type="StaticBody" parent="MeshSpatial" index="0"]
input_ray_pickable = true
input_capture_on_drag = false
collision_layer = 1
collision_mask = 1
friction = 1.0
bounce = 0.0
constant_linear_velocity = Vector3( 0, 0, 0 )
constant_angular_velocity = Vector3( 0, 0, 0 )
_sections_unfolded = [ "Collision" ]
[node name="CollisionShape" type="CollisionShape" parent="MeshSpatial/StaticBody" index="0"]
shape = SubResource( 6 )
disabled = false
[node name="Camera" type="Camera" parent="." index="1"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 10 )

View File

@ -1,11 +1,14 @@
extends KinematicBody
const norm_gravity = -80
var velocity = Vector3()
const MAX_SLOPE_ANGLE = 60
func _ready():
print("player init")
func _physics_process(delta):
# Keyboard input
var direction = Vector3()
if Input.is_action_pressed("ui_up"):
@ -20,9 +23,15 @@ func _physics_process(delta):
direction.y = 0
direction = direction.normalized()
var speed = 0.2
# Speep
var speed = 2.0
direction *= speed
self.translate(direction)
# Gravity
direction.y = norm_gravity * delta
# Collision
velocity = move_and_slide(direction, Vector3(0,1,0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
func _process(delta):
# Called every frame. Delta is time since last frame.

Binary file not shown.