Add files via upload

master
AiTechEye 2020-03-04 20:29:48 +01:00 committed by GitHub
parent 6deaa42a0b
commit 7d72d03299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 179 additions and 0 deletions

45
Spatial.tscn Normal file
View File

@ -0,0 +1,45 @@
[gd_scene load_steps=8 format=2]
[ext_resource path="res://player.gd" type="Script" id=1]
[sub_resource type="CubeMesh" id=1]
[sub_resource type="SpatialMaterial" id=2]
albedo_color = Color( 0, 0, 1, 1 )
[sub_resource type="BoxShape" id=3]
[sub_resource type="BoxShape" id=4]
[sub_resource type="CubeMesh" id=5]
[sub_resource type="SpatialMaterial" id=6]
albedo_color = Color( 0.054902, 0.509804, 0, 1 )
[node name="Spatial" type="Spatial"]
[node name="player" type="Spatial" parent="."]
script = ExtResource( 1 )
[node name="Camera" type="Camera" parent="player"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 6.99056 )
[node name="character" type="KinematicBody" parent="player"]
transform = Transform( 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0 )
[node name="MeshInstance" type="MeshInstance" parent="player/character"]
mesh = SubResource( 1 )
material/0 = SubResource( 2 )
[node name="CollisionShape" type="CollisionShape" parent="player/character"]
shape = SubResource( 3 )
[node name="ground" type="StaticBody" parent="."]
transform = Transform( 10, 0, 0, 0, 0.1, 0, 0, 0, 10, 0, -2.31381, 0 )
[node name="CollisionShape" type="CollisionShape" parent="ground"]
shape = SubResource( 4 )
[node name="MeshInstance" type="MeshInstance" parent="ground"]
mesh = SubResource( 5 )
material/0 = SubResource( 6 )

7
default_env.tres Normal file
View 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 )

103
player.gd Normal file
View File

@ -0,0 +1,103 @@
extends Spatial
var camera
var character
var direction = Vector3()
var velocity = Vector3()
var view = {
"tpv_camera_speed": 0.001,
"tpv_x":0,
"tpv_y":1,
"tpv_yheight":1,
"tpv_radio":4,
"tpv_radio_max":8,
"tpv_radio_min":3.5,
}
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
character = $character
camera = $Camera
camera.current = true
camera.far = 700
func _physics_process(delta):
if Input.is_key_pressed(KEY_ENTER) or Input.is_key_pressed(KEY_ESCAPE):
get_tree().quit()
return
var target = character.global_transform.origin
if target.y < view.tpv_yheight:
view.tpv_yheight -= (view.tpv_yheight-target.y) * 0.1
elif target.y > view.tpv_yheight:
view.tpv_yheight += (target.y-view.tpv_yheight) * 0.1
var r = Vector3(target.x+cos(view.tpv_x)*view.tpv_radio, view.tpv_yheight+view.tpv_y, target.z+sin(view.tpv_x)*view.tpv_radio)
camera.look_at_from_position(r,target,Vector3(0,1,0))
walk(delta)
func walk(delta):
direction = Vector3()
var aim = camera.get_global_transform().basis
var jump = false
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
if Input.is_key_pressed(KEY_SPACE):
jump = true
direction = direction.normalized()
#gravity
velocity.y -= 20 * delta
var on_ground = character.is_on_floor()
if jump and on_ground:
velocity.y = 10
elif on_ground:
velocity.y = 0
#adjust velocity
var v = velocity.linear_interpolate(direction * 10,10 * delta)
velocity = Vector3(v.x,velocity.y,v.z)
character.move_and_slide(velocity,Vector3(0,1,0))
if direction != Vector3():
rotating(direction)
func _input(event):
if event is InputEventMouseMotion:
#add camera side value
view.tpv_x += event.relative.x * view.tpv_camera_speed
#add camera height value
var y = view.tpv_y + (event.relative.y * view.tpv_camera_speed*10)
if y > 1 and y < 5: # min/max height
view.tpv_y = y
elif event is InputEventMouseButton:
#distance to the player
if event.button_index == BUTTON_WHEEL_DOWN and view.tpv_radio+0.1 < view.tpv_radio_max:
view.tpv_radio += 0.1
elif event.button_index == BUTTON_WHEEL_UP and view.tpv_radio-0.1 > view.tpv_radio_min:
view.tpv_radio -= 0.1
func rotating(dir,set = false):
if set:
character.rotation.y = atan2(dir.x* -1, dir.z* -1)
return
var a = atan2(dir.x* -1, dir.z* -1)
var rot = character.get_rotation()
if abs(rot.y-a) > PI:
var m = PI * 2
var d = fmod(a-rot.y,m)
a = rot.y + (fmod(2 * d,m)-d)*0.2
else:
a = lerp(rot.y,a,0.1)
character.rotation.y = a

24
project.godot Normal file
View File

@ -0,0 +1,24 @@
; 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="third person view"
run/main_scene="res://Spatial.tscn"
config/icon="res://icon.png"
[rendering]
environment/default_environment="res://default_env.tres"