divers essai de collisions.

This commit is contained in:
osquallo 2018-07-25 16:12:12 +02:00
parent 179b23ca61
commit 6518be5f63
5 changed files with 150 additions and 74 deletions

13
scenes/Game/Box.gd Normal file
View file

@ -0,0 +1,13 @@
extends RigidBody
var hit_timer = 0
func _process(delta):
if hit_timer >0:
hit_timer -= delta
if hit_timer <= 0:
$MeshInstance.get_surface_material(0).albedo_color = Color(1,1,1,1)
func hit():
$MeshInstance.get_surface_material(0).albedo_color = Color(1,0,0, 1)
hit_timer = 1

View file

@ -12,6 +12,7 @@ const MAX_SLOPE_ANGLE = 40
var camera_rotation
var camera
var flashlight
var MOUSE_SENSITIVITY = 0.05
@ -19,6 +20,7 @@ var MOUSE_SENSITIVITY = 0.05
func _ready():
camera_rotation = $Camera_rotation_helper
camera = $Camera_rotation_helper/Camera
flashlight = $MeshInstance/Flashlight
func _process(delta):
process_input(delta)
@ -78,7 +80,20 @@ func process_movement(delta):
hvel = hvel.linear_interpolate(target, accel*delta)
vel.x = hvel.x
vel.z = hvel.z
vel = move_and_slide(vel,Vector3(0,1,0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
# vel = move_and_slide(vel,Vector3(0,1,0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
var collision_info = move_and_collide(vel * delta)
if collision_info:
vel = vel.bounce(collision_info.normal)
if collision_info.collider.is_class("Node"):
if collision_info.collider.name == "Box":
var obj = collision_info.collider
if obj.has_method( "hit" ):
obj.hit()
print(obj.name)
# print(str(collision_info.collider.get_class()))
func _input(event):
@ -109,8 +124,13 @@ func _input(event):
camera.translation.y = old_y_translation
camera.translation.z = clamp(camera.translation.z, 0, 5)
if event.is_action_pressed( "game_flashlight" ) and not event.is_echo():
camera.get_node( "Flashlight" ).visible = not camera.get_node( "Flashlight" ).visible
# if event.is_action_pressed( "game_flashlight" ) and not event.is_echo():
# get_node( "Flashlight" ).visible = not get_node( "Flashlight" ).visible
if Input.is_action_just_pressed("game_flashlight"):
if flashlight.is_visible_in_tree():
flashlight.hide()
else:
flashlight.show()
if Input.is_action_pressed( "hide_char" ):
$MeshInstance.visible = not $MeshInstance.visible

View file

@ -2,6 +2,10 @@
[ext_resource path="res://scenes/Game/Character/Character.gd" type="Script" id=1]
[sub_resource type="SphereShape" id=2]
radius = 0.897042
[sub_resource type="SphereMesh" id=1]
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
@ -11,10 +15,6 @@ radial_segments = 64
rings = 32
is_hemisphere = false
[sub_resource type="SphereShape" id=2]
radius = 0.973349
[node name="Character" type="KinematicBody"]
transform = Transform( 1, 0, 0, 0, 0.589355, 0, 0, 0, 1, -0.0409546, 1.06519, 6.02408 )
@ -32,30 +32,9 @@ collision/safe_margin = 0.001
script = ExtResource( 1 )
_sections_unfolded = [ "Axis Lock", "collision" ]
[node name="MeshInstance" type="MeshInstance" parent="." index="0"]
[node name="Camera_rotation_helper" type="Spatial" parent="." index="0"]
transform = Transform( 0.573532, 0, 0, 0, 1, 0, 0, 0, 0.546204, 0.0433697, 4.3256, 0 )
layers = 1
material_override = null
cast_shadow = 1
extra_cull_margin = 0.0
use_in_baked_light = false
lod_min_distance = 0.0
lod_min_hysteresis = 0.0
lod_max_distance = 0.0
lod_max_hysteresis = 0.0
mesh = SubResource( 1 )
skeleton = NodePath("..")
material/0 = null
[node name="CollisionShape" type="CollisionShape" parent="." index="1"]
transform = Transform( 0.784282, 0, 0, 0, -5.90296e-08, -1.35044, 0, 0.791087, -3.45795e-08, 0.0505983, 4.32164, 0 )
shape = SubResource( 2 )
disabled = false
_sections_unfolded = [ "Transform" ]
[node name="Camera_rotation_helper" type="Spatial" parent="." index="2"]
editor/display_folded = true
[node name="Camera" type="Camera" parent="Camera_rotation_helper" index="0"]
@ -74,8 +53,32 @@ near = 0.05
far = 100.0
_sections_unfolded = [ "Transform" ]
[node name="Flashlight" type="SpotLight" parent="Camera_rotation_helper/Camera" index="0"]
[node name="CollisionShape" type="CollisionShape" parent="." index="1"]
transform = Transform( 0.364654, 0, 0, 0, -2.47558e-08, -0.566346, 0, 0.313738, -1.37139e-08, 0.0505983, 4.32164, 0 )
shape = SubResource( 2 )
disabled = false
_sections_unfolded = [ "Transform" ]
[node name="MeshInstance" type="MeshInstance" parent="." index="2"]
transform = Transform( 0.281766, 0, 0, 0, 0.491282, 0, 0, 0, 0.26834, 0.0433697, 4.3256, 0 )
layers = 1
material_override = null
cast_shadow = 1
extra_cull_margin = 0.0
use_in_baked_light = false
lod_min_distance = 0.0
lod_min_hysteresis = 0.0
lod_max_distance = 0.0
lod_max_hysteresis = 0.0
mesh = SubResource( 1 )
skeleton = NodePath("..")
material/0 = null
[node name="Flashlight" type="SpotLight" parent="MeshInstance" index="0"]
transform = Transform( 1.74358, 0, 0, 0, 0.999973, 0.0124571, 0, -0.00792279, 1.83077, -0.0756186, 0.00765181, -1.31515 )
visible = false
layers = 1
light_color = Color( 1, 1, 1, 1 )
@ -91,9 +94,9 @@ shadow_bias = 0.15
shadow_contact = 0.0
shadow_reverse_cull_face = true
editor_only = false
spot_range = 7.5843
spot_range = 9.90764
spot_attenuation = 1.0
spot_angle = 41.0327
spot_angle = 22.2473
spot_angle_attenuation = 1.0
_sections_unfolded = [ "Light", "Shadow" ]

View file

@ -1,33 +1,67 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=4 format=2]
[sub_resource type="CubeMesh" id=1]
[sub_resource type="SphereMesh" id=3]
size = Vector3( 2, 2, 2 )
subdivide_width = 0
subdivide_height = 0
subdivide_depth = 0
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
radius = 1.0
height = 2.0
radial_segments = 64
rings = 32
is_hemisphere = false
[sub_resource type="Shader" id=2]
code = "shader_type spatial;
varying vec3 some_color;
void vertex() {
some_color = NORMAL; // make the normal the color
}
void fragment() {
ALBEDO = some_color;
}"
_sections_unfolded = [ "Resource" ]
[sub_resource type="ShaderMaterial" id=3]
[sub_resource type="SpatialMaterial" id=4]
render_priority = 0
shader = SubResource( 2 )
_sections_unfolded = [ "Resource" ]
flags_transparent = false
flags_unshaded = false
flags_vertex_lighting = false
flags_no_depth_test = false
flags_use_point_size = false
flags_world_triplanar = false
flags_fixed_size = false
flags_albedo_tex_force_srgb = false
vertex_color_use_as_albedo = false
vertex_color_is_srgb = false
params_diffuse_mode = 0
params_specular_mode = 0
params_blend_mode = 0
params_cull_mode = 0
params_depth_draw_mode = 0
params_line_width = 1.0
params_point_size = 1.0
params_billboard_mode = 0
params_grow = false
params_use_alpha_scissor = false
albedo_color = Color( 1, 0.152344, 0.867554, 1 )
metallic = 0.0
metallic_specular = 0.5
metallic_texture_channel = 0
roughness = 0.0
roughness_texture_channel = 0
emission_enabled = false
normal_enabled = false
rim_enabled = false
clearcoat_enabled = false
anisotropy_enabled = false
ao_enabled = false
depth_enabled = false
subsurf_scatter_enabled = false
transmission_enabled = false
refraction_enabled = false
detail_enabled = false
uv1_scale = Vector3( 1, 1, 1 )
uv1_offset = Vector3( 0, 0, 0 )
uv1_triplanar = false
uv1_triplanar_sharpness = 1.0
uv2_scale = Vector3( 1, 1, 1 )
uv2_offset = Vector3( 0, 0, 0 )
uv2_triplanar = false
uv2_triplanar_sharpness = 1.0
proximity_fade_enable = false
distance_fade_enable = false
_sections_unfolded = [ "Albedo" ]
[sub_resource type="ConvexPolygonShape" id=4]
[sub_resource type="ConvexPolygonShape" id=2]
points = PoolVector3Array( -1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, 1, -1, -1 )
@ -70,14 +104,14 @@ lod_min_distance = 0.0
lod_min_hysteresis = 0.0
lod_max_distance = 0.0
lod_max_hysteresis = 0.0
mesh = SubResource( 1 )
mesh = SubResource( 3 )
skeleton = NodePath("..")
material/0 = SubResource( 3 )
material/0 = SubResource( 4 )
_sections_unfolded = [ "material" ]
[node name="CollisionShape" type="CollisionShape" parent="." index="1"]
shape = SubResource( 4 )
shape = SubResource( 2 )
disabled = false

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=21 format=2]
[gd_scene load_steps=22 format=2]
[ext_resource path="res://scenes/Game/Character/Character.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/Game/Brick08/Bricks08_col.jpg" type="Texture" id=2]
@ -6,10 +6,11 @@
[ext_resource path="res://assets/Game/Brick08/Bricks08_disp.jpg" type="Texture" id=4]
[ext_resource path="res://assets/Game/Brick08/Bricks08_nrm.jpg" type="Texture" id=5]
[ext_resource path="res://assets/Game/Brick08/Bricks08_rgh.jpg" type="Texture" id=6]
[ext_resource path="res://scenes/Game/CubeShaderTest.tscn" type="PackedScene" id=7]
[ext_resource path="res://scenes/Game/firecamp.tscn" type="PackedScene" id=8]
[ext_resource path="res://assets/Game/textures/fire_01.png" type="Texture" id=9]
[ext_resource path="res://assets/Game/textures/fire_02.png" type="Texture" id=10]
[ext_resource path="res://scenes/Game/Box.gd" type="Script" id=7]
[ext_resource path="res://scenes/Game/CubeShaderTest.tscn" type="PackedScene" id=8]
[ext_resource path="res://scenes/Game/firecamp.tscn" type="PackedScene" id=9]
[ext_resource path="res://assets/Game/textures/fire_01.png" type="Texture" id=10]
[ext_resource path="res://assets/Game/textures/fire_02.png" type="Texture" id=11]
[sub_resource type="PlaneMesh" id=1]
@ -191,7 +192,7 @@ particles_anim_h_frames = 1
particles_anim_v_frames = 1
particles_anim_loop = 0
albedo_color = Color( 0.390625, 0.390625, 0.390625, 1 )
albedo_texture = ExtResource( 9 )
albedo_texture = ExtResource( 10 )
metallic = 0.0
metallic_specular = 0.5
metallic_texture_channel = 0
@ -257,7 +258,7 @@ particles_anim_h_frames = 1
particles_anim_v_frames = 1
particles_anim_loop = 0
albedo_color = Color( 0.390625, 0.390625, 0.390625, 1 )
albedo_texture = ExtResource( 10 )
albedo_texture = ExtResource( 11 )
metallic = 0.0
metallic_specular = 0.5
metallic_texture_channel = 0
@ -268,7 +269,7 @@ emission = Color( 1, 0.886353, 0.617188, 1 )
emission_energy = 1.0
emission_operator = 0
emission_on_uv2 = false
emission_texture = ExtResource( 10 )
emission_texture = ExtResource( 11 )
normal_enabled = false
rim_enabled = false
clearcoat_enabled = false
@ -305,6 +306,8 @@ size = Vector2( 0.4, 0.4 )
[node name="Terrain" type="Spatial" parent="World" index="0"]
editor/display_folded = true
[node name="Ground" type="StaticBody" parent="World/Terrain" index="0"]
input_ray_pickable = true
@ -515,7 +518,7 @@ input_capture_on_drag = false
collision_layer = 1
collision_mask = 1
mode = 0
mass = 1.0
mass = 100.0
friction = 1.0
bounce = 0.0
gravity_scale = 1.0
@ -535,6 +538,7 @@ linear_velocity = Vector3( 0, 0, 0 )
linear_damp = -1.0
angular_velocity = Vector3( 0, 0, 0 )
angular_damp = -1.0
script = ExtResource( 7 )
[node name="MeshInstance" type="MeshInstance" parent="World/Box" index="0"]
@ -560,11 +564,13 @@ shape = SubResource( 6 )
disabled = false
_sections_unfolded = [ "Transform" ]
[node name="CubeShaderTest" parent="World" index="3" instance=ExtResource( 7 )]
[node name="CubeShaderTest" parent="World" index="3" instance=ExtResource( 8 )]
transform = Transform( -0.471909, 0, -0.881647, 0, 1, 0, 0.881647, 0, -0.471909, 4, 2, 3.11353 )
friction = 0.2
bounce = 0.75
[node name="fire_01" parent="World" index="4" instance=ExtResource( 8 )]
[node name="fire_01" parent="World" index="4" instance=ExtResource( 9 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.60514, 0.220215, -2.3728 )
visibility_aabb = AABB( -4, -4.04395, -3.96729, 8, 8, 8 )