diff options
author | Malfurious <m@lfurio.us> | 2022-07-17 21:11:44 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2022-07-17 21:11:44 -0400 |
commit | 4a9ff23bb13bfe5c182222fdb4314afc4f5c1fa8 (patch) | |
tree | 78c01d91420317c472afc9111b8d3e1d9ed8e085 | |
parent | 8c70036b4396fc909f0acf22e76d6f4da185a0b7 (diff) | |
parent | d9f1c33887761b8bcbc143e6d4582d634a9fd6ce (diff) | |
download | project-s-4a9ff23bb13bfe5c182222fdb4314afc4f5c1fa8.tar.gz project-s-4a9ff23bb13bfe5c182222fdb4314afc4f5c1fa8.zip |
Merge branch 'initial-character-behavior'
* initial-character-behavior:
Add view model implementing character movement
Define basic key bindings
Add placeholder character object
Add generic weapon
Diffstat (limited to '')
-rw-r--r-- | assets/characters/base_character/BaseCharacter.tscn | 27 | ||||
-rw-r--r-- | assets/characters/base_character/enemy_material.tres | 4 | ||||
-rw-r--r-- | assets/characters/base_character/friendly_material.tres | 4 | ||||
-rw-r--r-- | assets/maps/misc/dev_plane/DevPlane.tscn | 7 | ||||
-rw-r--r-- | assets/view_model/ViewModel.gd | 61 | ||||
-rw-r--r-- | assets/view_model/ViewModel.tscn | 18 | ||||
-rw-r--r-- | assets/weapons/goo_gun/GooGun.tscn | 44 | ||||
-rw-r--r-- | assets/weapons/goo_gun/gun_material.tres | 4 | ||||
-rw-r--r-- | assets/weapons/goo_gun/tank_material.tres | 4 | ||||
-rw-r--r-- | project.godot | 115 |
10 files changed, 285 insertions, 3 deletions
diff --git a/assets/characters/base_character/BaseCharacter.tscn b/assets/characters/base_character/BaseCharacter.tscn new file mode 100644 index 0000000..191e581 --- /dev/null +++ b/assets/characters/base_character/BaseCharacter.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://assets/weapons/goo_gun/GooGun.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/characters/base_character/friendly_material.tres" type="Material" id=2] + +[sub_resource type="CapsuleMesh" id=1] +material = ExtResource( 2 ) +radius = 0.3 +mid_height = 0.9 + +[sub_resource type="CapsuleShape" id=2] +radius = 0.3 +height = 0.9 + +[node name="BaseCharacter" type="KinematicBody"] + +[node name="Body" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 ) +mesh = SubResource( 1 ) +material/0 = null + +[node name="GooGun" parent="." instance=ExtResource( 1 )] +transform = Transform( -0.3, 0, -2.62268e-08, 0, 0.3, 0, 2.62268e-08, 0, -0.3, 0.425, 0.125, -0.1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 ) +shape = SubResource( 2 ) diff --git a/assets/characters/base_character/enemy_material.tres b/assets/characters/base_character/enemy_material.tres new file mode 100644 index 0000000..2e2d6ed --- /dev/null +++ b/assets/characters/base_character/enemy_material.tres @@ -0,0 +1,4 @@ +[gd_resource type="SpatialMaterial" format=2] + +[resource] +albedo_color = Color( 0.960784, 0.294118, 0.294118, 1 ) diff --git a/assets/characters/base_character/friendly_material.tres b/assets/characters/base_character/friendly_material.tres new file mode 100644 index 0000000..3f2d91f --- /dev/null +++ b/assets/characters/base_character/friendly_material.tres @@ -0,0 +1,4 @@ +[gd_resource type="SpatialMaterial" format=2] + +[resource] +albedo_color = Color( 0.203922, 0.713726, 0.952941, 1 ) diff --git a/assets/maps/misc/dev_plane/DevPlane.tscn b/assets/maps/misc/dev_plane/DevPlane.tscn index 228e30b..a17a112 100644 --- a/assets/maps/misc/dev_plane/DevPlane.tscn +++ b/assets/maps/misc/dev_plane/DevPlane.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://assets/maps/misc/dev_plane/tile_color.png" type="Texture" id=1] +[ext_resource path="res://assets/view_model/ViewModel.tscn" type="PackedScene" id=2] [sub_resource type="SpatialMaterial" id=6] albedo_texture = ExtResource( 1 ) @@ -29,8 +30,8 @@ transform = Transform( -4.37114e-08, -0.292372, 0.956305, 0, 0.956305, 0.292372, shadow_enabled = true directional_shadow_blend_splits = true -[node name="Camera" type="Camera" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.70758, 7.29223 ) +[node name="ViewModel" parent="." instance=ExtResource( 2 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 12 ) [node name="Geometry" type="Spatial" parent="."] diff --git a/assets/view_model/ViewModel.gd b/assets/view_model/ViewModel.gd new file mode 100644 index 0000000..7d5ce70 --- /dev/null +++ b/assets/view_model/ViewModel.gd @@ -0,0 +1,61 @@ +extends Spatial + +export var aim_sensitivity = 0.035 +export var movement_speed = 7 +export var jump_strength = 12.5 +export var gravity = 35 + +var velocity = Vector3.ZERO +var snap = Vector3.DOWN + +onready var character = $BaseCharacter +onready var anchor = $Anchor +onready var spring_arm = $Anchor/SpringArm + +func _ready(): + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + +func _process(_delta): + # The character model and the spring arm anchor are independent to allow them to rotate + # independently. Recouple their translations here so that the camera follows the model through + # space. + anchor.translation = character.translation + +func _physics_process(delta): + # Intended movement direction with the rotational angle adjusted by the camera's aim direction + var move_direction = Vector3.ZERO + move_direction.x = Input.get_action_strength("right") - Input.get_action_strength("left") + move_direction.z = Input.get_action_strength("back") - Input.get_action_strength("forward") + move_direction = move_direction.rotated(Vector3.UP, spring_arm.rotation.y).normalized() + + # Update velocity by new movement direction and continued effect of "gravity" + velocity.x = move_direction.x * movement_speed + velocity.z = move_direction.z * movement_speed + velocity.y -= gravity * delta + + # Snap vector management: set to ZERO to enable jumping, DOWN otherwise to stick to surfaces. + # Allow jump action for only one frame if already standing on a floor. + var just_landed = character.is_on_floor() and snap == Vector3.ZERO + var jump = character.is_on_floor() and Input.is_action_just_pressed("jump") + if jump: + velocity.y = jump_strength + snap = Vector3.ZERO + elif just_landed: + snap = Vector3.DOWN + + # Move character. Param 4 (true) means stop on slopes + velocity = character.move_and_slide_with_snap(velocity, snap, Vector3.UP, true) + + # Update character look direction if moved + if move_direction.length() > 0.2: + var look_direction = Vector2(-velocity.z, -velocity.x) + character.rotation.y = look_direction.angle() + +func _unhandled_input(event): + # Implement mouse aim direction + if event is InputEventMouseMotion: + spring_arm.rotation_degrees.x -= event.relative.y * aim_sensitivity + spring_arm.rotation_degrees.x = clamp(spring_arm.rotation_degrees.x, -90, 90) + + spring_arm.rotation_degrees.y -= event.relative.x * aim_sensitivity + spring_arm.rotation_degrees.y = wrapf(spring_arm.rotation_degrees.y, 0, 360) diff --git a/assets/view_model/ViewModel.tscn b/assets/view_model/ViewModel.tscn new file mode 100644 index 0000000..39fffb5 --- /dev/null +++ b/assets/view_model/ViewModel.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://assets/characters/base_character/BaseCharacter.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/view_model/ViewModel.gd" type="Script" id=2] + +[node name="ViewModel" type="Spatial"] +script = ExtResource( 2 ) + +[node name="BaseCharacter" parent="." instance=ExtResource( 1 )] + +[node name="Anchor" type="Spatial" parent="."] + +[node name="SpringArm" type="SpringArm" parent="Anchor"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0 ) +spring_length = 4.0 +margin = 0.05 + +[node name="Camera" type="Camera" parent="Anchor/SpringArm"] diff --git a/assets/weapons/goo_gun/GooGun.tscn b/assets/weapons/goo_gun/GooGun.tscn new file mode 100644 index 0000000..f0b9622 --- /dev/null +++ b/assets/weapons/goo_gun/GooGun.tscn @@ -0,0 +1,44 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://assets/weapons/goo_gun/gun_material.tres" type="Material" id=1] +[ext_resource path="res://assets/weapons/goo_gun/tank_material.tres" type="Material" id=2] + +[sub_resource type="CubeMesh" id=1] +material = ExtResource( 1 ) +size = Vector3( 0.25, 0.25, 2 ) + +[sub_resource type="CapsuleMesh" id=2] +material = ExtResource( 2 ) +radius = 0.275 +mid_height = 0.618 + +[sub_resource type="CubeMesh" id=3] +material = ExtResource( 1 ) +size = Vector3( 0.15, 0.5, 0.15 ) + +[sub_resource type="CylinderMesh" id=4] +material = ExtResource( 1 ) +top_radius = 0.24 +bottom_radius = 0.088 +height = 0.429 + +[node name="GooGun" type="Spatial"] + +[node name="Body" type="MeshInstance" parent="."] +mesh = SubResource( 1 ) +material/0 = null + +[node name="Tank" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.398, -0.375 ) +mesh = SubResource( 2 ) +material/0 = null + +[node name="Handle" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.373, -0.27 ) +mesh = SubResource( 3 ) +material/0 = null + +[node name="Nozzle" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.953 ) +mesh = SubResource( 4 ) +material/0 = null diff --git a/assets/weapons/goo_gun/gun_material.tres b/assets/weapons/goo_gun/gun_material.tres new file mode 100644 index 0000000..08bf630 --- /dev/null +++ b/assets/weapons/goo_gun/gun_material.tres @@ -0,0 +1,4 @@ +[gd_resource type="SpatialMaterial" format=2] + +[resource] +albedo_color = Color( 0.317647, 1, 0.14902, 1 ) diff --git a/assets/weapons/goo_gun/tank_material.tres b/assets/weapons/goo_gun/tank_material.tres new file mode 100644 index 0000000..c8b98a4 --- /dev/null +++ b/assets/weapons/goo_gun/tank_material.tres @@ -0,0 +1,4 @@ +[gd_resource type="SpatialMaterial" format=2] + +[resource] +albedo_color = Color( 1, 0.423529, 0.0509804, 1 ) diff --git a/project.godot b/project.godot index a580a95..68207b1 100644 --- a/project.godot +++ b/project.godot @@ -21,6 +21,121 @@ window/size/width=1920 window/size/height=1080 window/size/resizable=false +[input] + +ui_accept={ +"deadzone": 0.5, +"events": [ ] +} +ui_select={ +"deadzone": 0.5, +"events": [ ] +} +ui_cancel={ +"deadzone": 0.5, +"events": [ ] +} +ui_focus_next={ +"deadzone": 0.5, +"events": [ ] +} +ui_focus_prev={ +"deadzone": 0.5, +"events": [ ] +} +ui_left={ +"deadzone": 0.5, +"events": [ ] +} +ui_right={ +"deadzone": 0.5, +"events": [ ] +} +ui_up={ +"deadzone": 0.5, +"events": [ ] +} +ui_down={ +"deadzone": 0.5, +"events": [ ] +} +ui_page_up={ +"deadzone": 0.5, +"events": [ ] +} +ui_page_down={ +"deadzone": 0.5, +"events": [ ] +} +ui_home={ +"deadzone": 0.5, +"events": [ ] +} +ui_end={ +"deadzone": 0.5, +"events": [ ] +} +fire={ +"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) + ] +} +altfire={ +"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) + ] +} +forward={ +"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":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +back={ +"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":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +left={ +"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":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +right={ +"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":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +jump={ +"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":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +movement={ +"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":16777237,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +ability_1={ +"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":69,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +ability_2={ +"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":81,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +ping={ +"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":70,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +info={ +"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":16777218,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} + [physics] common/enable_pause_aware_picking=true |