Compare commits
6 commits
e16f87cbfa
...
54967e570b
| Author | SHA1 | Date | |
|---|---|---|---|
| 54967e570b | |||
| 35a17c04b6 | |||
| ee44810636 | |||
| d00cee752e | |||
| 79fa813571 | |||
| b11655a8fe |
5 changed files with 104 additions and 111 deletions
20
main.tscn
20
main.tscn
|
|
@ -1,12 +1,13 @@
|
|||
[gd_scene load_steps=16 format=3 uid="uid://eiaw4xbs3suk"]
|
||||
[gd_scene load_steps=17 format=3 uid="uid://eiaw4xbs3suk"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://qb8cbljxgnub" path="res://world/killbrick.tscn" id="1_h2yge"]
|
||||
[ext_resource type="PackedScene" uid="uid://cfceg80unq0pe" path="res://player/player.tscn" id="1_ig7tw"]
|
||||
[ext_resource type="PackedScene" uid="uid://bcmrj6qkemrll" path="res://world/radiohead_cube.tscn" id="2_0xm2m"]
|
||||
[ext_resource type="Texture2D" uid="uid://wdjmyv260he1" path="res://world/textures/grass.jpg" id="2_272bh"]
|
||||
[ext_resource type="Texture2D" uid="uid://dnt0vfav03ris" path="res://world/textures/grass.jpg" id="2_272bh"]
|
||||
[ext_resource type="PackedScene" uid="uid://of6tq8gpjxtu" path="res://gears/gear_pickup.tscn" id="3_lquwl"]
|
||||
[ext_resource type="PackedScene" uid="uid://bafl8q0r61xrg" path="res://gears/gear.tscn" id="4_7mycd"]
|
||||
[ext_resource type="Texture2D" uid="uid://2ku62tk8r74x" path="res://world/textures/sky.hdr" id="8_5vw27"]
|
||||
[ext_resource type="PackedScene" uid="uid://c117buhmmkvkt" path="res://gears/ball.tscn" id="6_5vw27"]
|
||||
[ext_resource type="PackedScene" uid="uid://d3k7b6o56ue5k" path="res://gears/geep.tscn" id="7_kek77"]
|
||||
[ext_resource type="Texture2D" uid="uid://bl4yvm44o6gcf" path="res://world/textures/sky.hdr" id="8_5vw27"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_7dm0k"]
|
||||
size = Vector3(1000, 2, 1000)
|
||||
|
|
@ -68,11 +69,16 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12, 7, 0)
|
|||
[node name="Killbrick" parent="." instance=ExtResource("1_h2yge")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -40, 1.5, -40)
|
||||
|
||||
[node name="GearPickup" parent="." instance=ExtResource("3_lquwl")]
|
||||
[node name="BallPickup" parent="." instance=ExtResource("3_lquwl")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12, 2, -21)
|
||||
|
||||
[node name="Gear" parent="GearPickup" instance=ExtResource("4_7mycd")]
|
||||
transform = Transform3D(1, 0, 0, 0, -0.012967386, 0.9999159, 0, -0.9999159, -0.012967386, 0, 0.5, 0)
|
||||
[node name="Gear" parent="BallPickup" instance=ExtResource("6_5vw27")]
|
||||
|
||||
[node name="GeepPickup" parent="." instance=ExtResource("3_lquwl")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8, 1.75, -30)
|
||||
|
||||
[node name="Gear" parent="GeepPickup" instance=ExtResource("7_kek77")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.75, 0)
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_7mycd")
|
||||
|
|
|
|||
87
player/camera.gd
Normal file
87
player/camera.gd
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
class_name CameraGimbal extends Node3D
|
||||
|
||||
@export var rotation_speed = (PI / 180) * 120
|
||||
@export var default_zoom = 8
|
||||
|
||||
# is mouse captured by game permanently?
|
||||
# (i.e. not just holding right click)
|
||||
var locked = false
|
||||
var mouse_velocity = Vector2.ZERO
|
||||
|
||||
var current_zoom = default_zoom
|
||||
var zoom_min = 4
|
||||
var zoom_max = 80
|
||||
var zoom_speed = 20
|
||||
|
||||
func _lock():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func _unlock():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
mouse_velocity = Vector2.ZERO
|
||||
|
||||
func lock():
|
||||
_lock()
|
||||
locked = true
|
||||
|
||||
# optional API function for nodes that want
|
||||
# to unlock the mouse for a period of time
|
||||
func unlock():
|
||||
_unlock()
|
||||
locked = false
|
||||
|
||||
func reset():
|
||||
basis = Basis()
|
||||
$InnerGimbal.basis = Basis()
|
||||
current_zoom = default_zoom
|
||||
|
||||
# y is before x because the outer gimbal is
|
||||
# in charge of rotating the y axis
|
||||
func rotate_camera(delta):
|
||||
var y = 0
|
||||
var x = 0
|
||||
|
||||
if mouse_velocity.x > 5 or mouse_velocity.x < -5:
|
||||
y -= clamp(mouse_velocity.x / 12.5, -10, 10)
|
||||
if mouse_velocity.y > 5 or mouse_velocity.y < -5:
|
||||
x -= clamp(mouse_velocity.y / 12.5, -10, 10)
|
||||
|
||||
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
||||
$InnerGimbal.rotate_object_local(
|
||||
Vector3.RIGHT, x * rotation_speed * delta)
|
||||
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -0.8, 0.7)
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_velocity = event.relative
|
||||
elif event.is_action_pressed("cam_zoom_out"):
|
||||
current_zoom += 1
|
||||
elif event.is_action_pressed("cam_zoom_in"):
|
||||
current_zoom -= 1
|
||||
|
||||
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
||||
|
||||
func _process(delta):
|
||||
# rotate camera
|
||||
if locked:
|
||||
rotate_camera(delta)
|
||||
else:
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
|
||||
_lock()
|
||||
rotate_camera(delta)
|
||||
else:
|
||||
_unlock()
|
||||
|
||||
# zoom in/out
|
||||
var pos = Vector3($InnerGimbal/Camera3D.position)
|
||||
pos.y = lerp(pos.y, float(current_zoom), zoom_speed * delta)
|
||||
pos.z = lerp(pos.z, float(current_zoom), zoom_speed * delta)
|
||||
|
||||
$InnerGimbal/Camera3D.position = pos
|
||||
|
||||
# reset camera
|
||||
if Input.is_action_pressed("cam_reset"):
|
||||
reset()
|
||||
|
||||
func _ready():
|
||||
lock()
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
class_name CameraGimbal extends Node3D
|
||||
|
||||
@export var rotation_speed = (PI / 180) * 120
|
||||
@export var shift_lock = false
|
||||
|
||||
var locked_mouse_positon = Vector2(0,0)
|
||||
var mouse_locked = false
|
||||
var mouse_x_velocity = 0
|
||||
var mouse_y_velocity = 0
|
||||
|
||||
var zoom_min = 4
|
||||
var zoom_max = 80
|
||||
var zoom_speed = 20
|
||||
var current_zoom = 8
|
||||
|
||||
func reset():
|
||||
basis = Basis()
|
||||
$InnerGimbal.basis = Basis()
|
||||
|
||||
func rotate_camera_y(y, delta):
|
||||
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
||||
func rotate_camera_x(x, delta):
|
||||
$InnerGimbal.rotate_object_local(
|
||||
Vector3.RIGHT, x * rotation_speed * delta)
|
||||
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x,-0.8,0.7)
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_x_velocity = event.relative.x
|
||||
mouse_y_velocity = event.relative.y
|
||||
elif event.is_action_pressed("zoom_out"):
|
||||
current_zoom += 1
|
||||
elif event.is_action_pressed("zoom_in"):
|
||||
current_zoom -= 1
|
||||
|
||||
func _process(delta):
|
||||
# rotate outer gimbal around y axis
|
||||
var y = 0
|
||||
var x = 0
|
||||
|
||||
if Input.is_action_just_pressed("shift_lock"):
|
||||
if shift_lock == true:
|
||||
shift_lock = false
|
||||
else:
|
||||
shift_lock = true
|
||||
elif Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or shift_lock == true:
|
||||
if mouse_locked == false:
|
||||
mouse_locked = true
|
||||
locked_mouse_positon = get_viewport().get_mouse_position()
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
if mouse_x_velocity > 5 or mouse_x_velocity < -5:
|
||||
y -= clamp(mouse_x_velocity / 12.5, -10, 10)
|
||||
if mouse_y_velocity > 5 or mouse_y_velocity < -5:
|
||||
x -= clamp(mouse_y_velocity / 12.5, -10, 10)
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
mouse_locked = false
|
||||
mouse_x_velocity = 0
|
||||
mouse_y_velocity = 0
|
||||
|
||||
rotate_camera_y(y, delta)
|
||||
rotate_camera_x(x, delta)
|
||||
|
||||
# reset gimbals
|
||||
if Input.is_action_pressed("cam_reset"):
|
||||
reset()
|
||||
|
||||
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
||||
|
||||
var pos = Vector3($InnerGimbal/Camera3D.position)
|
||||
pos.y = lerp(pos.y, float(current_zoom), zoom_speed*delta)
|
||||
pos.z = lerp(pos.z, float(current_zoom), zoom_speed*delta)
|
||||
|
||||
$InnerGimbal/Camera3D.position = pos
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=8 format=4 uid="uid://cfceg80unq0pe"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bfflnag3p4gen" path="res://player/player.gd" id="1_onrkg"]
|
||||
[ext_resource type="Script" uid="uid://oi6sint7jkc6" path="res://player/camera_gimbal.gd" id="2_onrkg"]
|
||||
[ext_resource type="Script" uid="uid://djeyfi7vm2vw0" path="res://player/player.gd" id="1_onrkg"]
|
||||
[ext_resource type="Script" uid="uid://oi6sint7jkc6" path="res://player/camera.gd" id="2_onrkg"]
|
||||
[ext_resource type="Texture2D" uid="uid://cfb0gbwm57hm4" path="res://models/player_0.png" id="3_hqtel"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_onrkg"]
|
||||
|
|
|
|||
|
|
@ -42,26 +42,6 @@ jump={
|
|||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_up={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_down={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_reset={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":79,"physical_keycode":0,"key_label":0,"unicode":111,"location":0,"echo":false,"script":null)
|
||||
|
|
@ -87,17 +67,12 @@ backpack_3={
|
|||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":51,"physical_keycode":0,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
shift_lock={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
zoom_in={
|
||||
cam_zoom_in={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
zoom_out={
|
||||
cam_zoom_out={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue