godot squash the creeps player movement
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Player.tscn" type="PackedScene" id=1]
|
||||
|
||||
[sub_resource type="BoxShape" id=1]
|
||||
extents = Vector3( 30, 1, 30 )
|
||||
@@ -21,3 +23,11 @@ material/0 = null
|
||||
[node name="DirectionalLight" type="DirectionalLight" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, -0.163205, 0.986592, 0, -0.986592, -0.163205, 0, 22.3151, 0 )
|
||||
shadow_enabled = true
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource( 1 )]
|
||||
|
||||
[node name="CameraPivot" type="Position3D" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 0.704176, 0.710026, 0, -0.710026, 0.704176, 0, 0, 0 )
|
||||
|
||||
[node name="Camera" type="Camera" parent="CameraPivot"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 19.0482 )
|
||||
|
@@ -1,11 +1,16 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://art/player.glb" type="PackedScene" id=1]
|
||||
[ext_resource path="res://build/src/Player.cs" type="Script" id=2]
|
||||
|
||||
[sub_resource type="SphereShape" id=1]
|
||||
radius = 0.79911
|
||||
|
||||
[node name="Player" type="KinematicBody"]
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"haxe_script": "res://scripts/Player.hx"
|
||||
}
|
||||
|
||||
[node name="Pivot" type="Spatial" parent="."]
|
||||
|
||||
|
@@ -16,6 +16,7 @@ nodes/root_name="Scene Root"
|
||||
nodes/root_scale=1.0
|
||||
nodes/custom_script=""
|
||||
nodes/storage=0
|
||||
nodes/use_legacy_names=true
|
||||
materials/location=1
|
||||
materials/storage=1
|
||||
materials/keep_on_reimport=true
|
||||
|
@@ -16,6 +16,7 @@ nodes/root_name="Scene Root"
|
||||
nodes/root_scale=1.0
|
||||
nodes/custom_script=""
|
||||
nodes/storage=0
|
||||
nodes/use_legacy_names=true
|
||||
materials/location=1
|
||||
materials/storage=1
|
||||
materials/keep_on_reimport=true
|
||||
|
@@ -4,5 +4,6 @@
|
||||
--define analyzer-optimize
|
||||
--class-path scripts
|
||||
--library godot
|
||||
--library kiss
|
||||
--macro godot.Godot.buildProject()
|
||||
--dce full
|
||||
|
@@ -39,6 +39,7 @@ _global_script_class_icons={
|
||||
[application]
|
||||
|
||||
config/name="Squash the Creeps (3D)"
|
||||
run/main_scene="res://Main.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[editor_plugins]
|
||||
@@ -73,7 +74,7 @@ move_forward={
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
move_back={
|
||||
move_backward={
|
||||
"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":16777234,"unicode":0,"echo":false,"script":null)
|
||||
, 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,"unicode":0,"echo":false,"script":null)
|
||||
|
14
projects/godot-squash-the-creeps-3d/scripts/Player.hx
Normal file
14
projects/godot-squash-the-creeps-3d/scripts/Player.hx
Normal file
@@ -0,0 +1,14 @@
|
||||
package;
|
||||
|
||||
import kiss.Prelude;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Player extends KinematicBody {
|
||||
// Don't forget to rebuild the project so the editor knows about the new export variable.
|
||||
// TODO is it possible to provide the export annotation from .kiss?
|
||||
// How fast the player moves in meters per second.
|
||||
@:export public var speed = 14;
|
||||
|
||||
// The downward acceleration when in the air, in meters per second squared.
|
||||
@:export public var fallAcceleration = 75;
|
||||
}
|
27
projects/godot-squash-the-creeps-3d/scripts/Player.kiss
Normal file
27
projects/godot-squash-the-creeps-3d/scripts/Player.kiss
Normal file
@@ -0,0 +1,27 @@
|
||||
(var &mut :Spatial pivot null)
|
||||
(var &mut :Vector3 _velocity Vector3.ZERO)
|
||||
|
||||
(method &public &override :Void _Ready []
|
||||
(set pivot (cast (getNode "Pivot") Spatial)))
|
||||
|
||||
(method &public &override :Void _PhysicsProcess [:Single delta]
|
||||
(let [&mut direction Vector3.ZERO]
|
||||
(when (Input.isActionPressed "move_right")
|
||||
(+= direction.x 1))
|
||||
(when (Input.isActionPressed "move_left")
|
||||
(-= direction.x 1))
|
||||
(when (Input.isActionPressed "move_backward")
|
||||
(+= direction.z 1))
|
||||
(when (Input.isActionPressed "move_forward")
|
||||
(-= direction.z 1))
|
||||
|
||||
(when !(= direction Vector3.ZERO)
|
||||
(set direction (direction.normalized))
|
||||
// TODO for some reason, the Vector3 addition operator is only found when used in a raw haxe expr:
|
||||
(pivot.lookAt #|translation + direction|# Vector3.UP))
|
||||
|
||||
(set _velocity.x (* direction.x speed))
|
||||
(set _velocity.z (* direction.z speed))
|
||||
(-= _velocity.y (* fallAcceleration delta))
|
||||
(set _velocity (moveAndSlide _velocity Vector3.UP))
|
||||
))
|
@@ -1,4 +1,4 @@
|
||||
import godot.*;
|
||||
import godot.GD.*;
|
||||
|
||||
using godot.Utils;
|
||||
// using godot.Utils;
|
||||
|
Reference in New Issue
Block a user