Add files via upload
This commit is contained in:
parent
1b31c53507
commit
50af5e0b16
82
KinematicBody.gd
Normal file
82
KinematicBody.gd
Normal file
@ -0,0 +1,82 @@
|
||||
extends KinematicBody
|
||||
|
||||
var direction = Vector3()
|
||||
var velocity = Vector3()
|
||||
|
||||
var gravity = -27
|
||||
var jump_height = 10
|
||||
var walk_speed = 10
|
||||
|
||||
var fpv_camera_angle = 0
|
||||
var fpv_mouse_sensitivity = 0.3
|
||||
# == phys
|
||||
var phys_area_object
|
||||
onready var phys_area = $head/Area
|
||||
onready var phys_area_aim = $head/Area/aim
|
||||
|
||||
|
||||
func _ready():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
$player_mesh.visible = false
|
||||
OS.set_window_position(Vector2(0,0))
|
||||
|
||||
# == control
|
||||
func _input(event):
|
||||
if Input.is_action_just_pressed("ui_cancel"):
|
||||
get_tree().quit()
|
||||
if event is InputEventMouseMotion:
|
||||
rotate_y(deg2rad(-event.relative.x * fpv_mouse_sensitivity))
|
||||
var change = -event.relative.y * fpv_mouse_sensitivity
|
||||
if change + fpv_camera_angle < 90 and change + fpv_camera_angle > -90:
|
||||
$head.rotate_x(deg2rad(change))
|
||||
fpv_camera_angle += change
|
||||
|
||||
# == phys
|
||||
|
||||
if Input.is_action_just_pressed("left_click"):
|
||||
for body in phys_area.get_overlapping_bodies():
|
||||
if body is RigidBody:
|
||||
phys_area_object = body
|
||||
return
|
||||
if Input.is_action_just_released("left_click"):
|
||||
phys_area_object = null
|
||||
if Input.is_action_just_pressed("right_click") and phys_area_object != null and weakref(phys_area_object).get_ref():
|
||||
var a = phys_area_aim.get_global_transform().origin
|
||||
var b = phys_area_object.get_global_transform().origin
|
||||
|
||||
phys_area_object.set_linear_velocity((b-a)*10)
|
||||
phys_area_object = null
|
||||
|
||||
# == phys
|
||||
|
||||
func _physics_process(delta):
|
||||
if phys_area_object != null and weakref(phys_area_object).get_ref():
|
||||
var a = phys_area.get_global_transform().origin
|
||||
var b = phys_area_object.get_global_transform().origin
|
||||
phys_area_object.set_linear_velocity((a-b)*10)
|
||||
if phys_area_object.get("timer") != null:
|
||||
phys_area_object.timer = 0
|
||||
|
||||
# == move
|
||||
|
||||
func _process(delta):
|
||||
direction = Vector3()
|
||||
var aim = $head/Camera.get_global_transform().basis
|
||||
if Input.is_key_pressed(KEY_W):
|
||||
direction -= aim.z
|
||||
if Input.is_key_pressed(KEY_S):
|
||||
direction += aim.z
|
||||
if Input.is_key_pressed(KEY_A):
|
||||
direction -= aim.x
|
||||
if Input.is_key_pressed(KEY_D):
|
||||
direction += aim.x
|
||||
direction = direction.normalized()
|
||||
velocity.y += gravity * delta
|
||||
var tv = velocity
|
||||
tv = velocity.linear_interpolate(direction * walk_speed,6 * delta)
|
||||
velocity.x = tv.x
|
||||
velocity.z = tv.z
|
||||
velocity = move_and_slide(velocity,Vector3(0,1,0))
|
||||
# == jumping
|
||||
if is_on_floor() and Input.is_key_pressed(KEY_SPACE):
|
||||
velocity.y = jump_height
|
BIN
default.png
Normal file
BIN
default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 395 B |
7
default_env.tres
Normal file
7
default_env.tres
Normal file
@ -0,0 +1,7 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
22
ground.tscn
Normal file
22
ground.tscn
Normal file
@ -0,0 +1,22 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[sub_resource type="CubeMesh" id=1]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=2]
|
||||
albedo_color = Color( 0.231373, 0.764706, 0.254902, 1 )
|
||||
|
||||
[sub_resource type="BoxShape" id=3]
|
||||
|
||||
[node name="Spatial" type="Spatial"]
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||
transform = Transform( 4.92945, 0, 0, 0, 1.02, 0, 0, 0, 4.90199, 0, -1, 0 )
|
||||
mesh = SubResource( 1 )
|
||||
material/0 = SubResource( 2 )
|
||||
|
||||
[node name="StaticBody" type="StaticBody" parent="MeshInstance"]
|
||||
transform = Transform( 0.202862, 0, 0, 0, 3.33333, 0, 0, 0, 0.203999, 0, 0, 0 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="MeshInstance/StaticBody"]
|
||||
transform = Transform( 4.92945, 0, 0, 0, 0.3, 0, 0, 0, 4.90199, 0, 0, 0 )
|
||||
shape = SubResource( 3 )
|
161
main.tscn
Normal file
161
main.tscn
Normal file
@ -0,0 +1,161 @@
|
||||
[gd_scene load_steps=16 format=2]
|
||||
|
||||
[ext_resource path="res://default.png" type="Texture" id=1]
|
||||
[ext_resource path="res://KinematicBody.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=1]
|
||||
albedo_texture = ExtResource( 1 )
|
||||
uv1_scale = Vector3( 10, 1, 10 )
|
||||
uv1_triplanar = true
|
||||
|
||||
[sub_resource type="CubeMesh" id=2]
|
||||
|
||||
[sub_resource type="BoxShape" id=3]
|
||||
|
||||
[sub_resource type="CubeMesh" id=4]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=5]
|
||||
albedo_color = Color( 1, 0, 0, 1 )
|
||||
|
||||
[sub_resource type="CapsuleShape" id=6]
|
||||
|
||||
[sub_resource type="BoxShape" id=7]
|
||||
|
||||
[sub_resource type="SphereShape" id=8]
|
||||
|
||||
[sub_resource type="SphereMesh" id=9]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=10]
|
||||
albedo_color = Color( 0, 0.670588, 0.0117647, 1 )
|
||||
|
||||
[sub_resource type="BoxShape" id=11]
|
||||
|
||||
[sub_resource type="CubeMesh" id=12]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=13]
|
||||
albedo_color = Color( 0, 0.0392157, 1, 1 )
|
||||
|
||||
[node name="Spatial" type="Spatial"]
|
||||
|
||||
[node name="Ground" type="MeshInstance" parent="."]
|
||||
editor/display_folded = true
|
||||
transform = Transform( 20.282, 0, 0, 0, 3.00821, 0, 0, 0, 19.2005, 0, -3.90285, -3.40485 )
|
||||
material_override = SubResource( 1 )
|
||||
mesh = SubResource( 2 )
|
||||
material/0 = null
|
||||
|
||||
[node name="StaticBody" type="StaticBody" parent="Ground"]
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="Ground/StaticBody"]
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="box1" type="MeshInstance" parent="."]
|
||||
editor/display_folded = true
|
||||
transform = Transform( 6.12884, 0, 0, 0, 3.00821, 0, 0, 0, 6.826, -8.45122, -1.0583, -13.336 )
|
||||
material_override = SubResource( 1 )
|
||||
mesh = SubResource( 2 )
|
||||
material/0 = null
|
||||
|
||||
[node name="StaticBody" type="StaticBody" parent="box1"]
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="box1/StaticBody"]
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="box2" type="MeshInstance" parent="."]
|
||||
editor/display_folded = true
|
||||
transform = Transform( 3.72134, 0, 0, 0, 1.8561, 0, 0, 0, 2.94374, 3.52478, -1.08219, -12.5602 )
|
||||
material_override = SubResource( 1 )
|
||||
mesh = SubResource( 2 )
|
||||
material/0 = null
|
||||
|
||||
[node name="StaticBody" type="StaticBody" parent="box2"]
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="box2/StaticBody"]
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="player" type="Spatial" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -8.65268, 0 )
|
||||
|
||||
[node name="KinematicBody" type="KinematicBody" parent="player"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8.07249, 1.84711 )
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="player_mesh" type="MeshInstance" parent="player/KinematicBody"]
|
||||
transform = Transform( 0.404405, 0, 0, 0, 0.893384, 0, 0, 0, 0.372423, 0, 1.54014, 0 )
|
||||
mesh = SubResource( 4 )
|
||||
material/0 = SubResource( 5 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="player/KinematicBody"]
|
||||
transform = Transform( 0.636057, 0, 0, 0, -4.37114e-008, -1, 0, 0.605457, -2.64654e-008, 0, 1.54517, 0 )
|
||||
shape = SubResource( 6 )
|
||||
|
||||
[node name="head" type="Spatial" parent="player/KinematicBody"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.66905, 0 )
|
||||
|
||||
[node name="Camera" type="Camera" parent="player/KinematicBody/head"]
|
||||
|
||||
[node name="Area" type="Area" parent="player/KinematicBody/head"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.241424, -2 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="player/KinematicBody/head/Area"]
|
||||
shape = SubResource( 7 )
|
||||
|
||||
[node name="aim" type="Spatial" parent="player/KinematicBody/head/Area"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3 )
|
||||
|
||||
[node name="ball" type="RigidBody" parent="."]
|
||||
editor/display_folded = true
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.02767, 0, -2.0248 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="ball"]
|
||||
shape = SubResource( 8 )
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="ball"]
|
||||
mesh = SubResource( 9 )
|
||||
material/0 = SubResource( 10 )
|
||||
|
||||
[node name="ball2" type="RigidBody" parent="."]
|
||||
editor/display_folded = true
|
||||
transform = Transform( 0.63416, 0, 0, 0, 0.63416, 0, 0, 0, 0.63416, -0.7296, 0, -2.0248 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="ball2"]
|
||||
shape = SubResource( 8 )
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="ball2"]
|
||||
mesh = SubResource( 9 )
|
||||
material/0 = SubResource( 10 )
|
||||
|
||||
[node name="cube" type="RigidBody" parent="."]
|
||||
editor/display_folded = true
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5.75055, 1, -0.45817 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="cube"]
|
||||
shape = SubResource( 11 )
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="cube"]
|
||||
mesh = SubResource( 12 )
|
||||
material/0 = SubResource( 13 )
|
||||
|
||||
[node name="cube2" type="RigidBody" parent="."]
|
||||
editor/display_folded = true
|
||||
transform = Transform( 0.408973, 0, 0, 0, 0.408973, 0, 0, 0, 0.408973, 2.49498, 1, -3.60651 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="cube2"]
|
||||
shape = SubResource( 11 )
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="cube2"]
|
||||
mesh = SubResource( 12 )
|
||||
material/0 = SubResource( 13 )
|
||||
|
||||
[node name="cube3" type="RigidBody" parent="."]
|
||||
editor/display_folded = true
|
||||
transform = Transform( 0.408973, 0, 0, 0, 0.408973, 0, 0, 0, 0.408973, -2.15019, 2.52685, -7.3701 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="cube3"]
|
||||
transform = Transform( 4.82578, 0, 0, 0, 0.393227, 0, 0, 0, 0.512657, 0, 0, 0 )
|
||||
shape = SubResource( 11 )
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="cube3"]
|
||||
transform = Transform( 4.82578, 0, 0, 0, 0.393227, 0, 0, 0, 0.512657, 0, 0, 0 )
|
||||
mesh = SubResource( 12 )
|
||||
material/0 = SubResource( 13 )
|
42
project.godot
Normal file
42
project.godot
Normal file
@ -0,0 +1,42 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=4
|
||||
|
||||
_global_script_classes=[ ]
|
||||
_global_script_class_icons={
|
||||
|
||||
}
|
||||
|
||||
[application]
|
||||
|
||||
config/name="physics object picking up"
|
||||
run/main_scene="res://main.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[input]
|
||||
|
||||
ui_accept={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
left_click={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
right_click={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
environment/default_environment="res://default_env.tres"
|
Loading…
x
Reference in New Issue
Block a user