Skip to content

Commit

Permalink
simple fly mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Apr 14, 2020
1 parent 2b8dcfb commit 33433e6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 46 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You then need to put the data and reports folder into a mcdata folder into the u

# Status

15.04.2020: simply fly mechanics
14.04.2020: Rewritten chunk rendering, now its actually working (kinda) https://i.imgur.com/0liIc2B.png
11.04.2020: Chunk rendering? Kinda? Maybe? https://i.imgur.com/sumfigG.png
10.04.2020: Movement! https://streamable.com/951xc2
Expand Down
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ movement_jump={
"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,"unicode":0,"echo":false,"script":null)
]
}
movement_sneak={
"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,"unicode":0,"echo":false,"script":null)
]
}

[mono]

Expand Down
1 change: 1 addition & 0 deletions scripts/Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Actions {
public static readonly string movement_walk_backwards = "movement_walk_backwards";
public static readonly string movement_walk_forwards = "movement_walk_forwards";
public static readonly string movement_jump = "movement_jump";
public static readonly string movement_sneak = "movement_sneak";

public static readonly string ui_up = "ui_up";
public static readonly string ui_down = "ui_down";
Expand Down
33 changes: 29 additions & 4 deletions scripts/objects/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Console = Godotcraft.scripts.objects.Console;

// taken from https://github.com/turtlewit/VineCrawler/blob/master/PlayerNew.gd
// flying by minidigger
public class Player : KinematicBody {
[Export] public float mouseSensitivity = .1f;

Expand All @@ -28,6 +29,7 @@ public class Player : KinematicBody {
private Vector3 playerVelocity;

private bool wishJump;
private bool flying;

private bool touchingGround;

Expand All @@ -45,15 +47,23 @@ public override void _Ready() {

public override void _PhysicsProcess(float delta) {
queueJump();
if (touchingGround) {
if (touchingGround || flying) {
groundMove(delta);
}
else {
airMove(delta);
}

if (flying) {
flyControls(delta);
}

playerVelocity = MoveAndSlide(playerVelocity, Vector3.Up);
touchingGround = IsOnFloor();

if (touchingGround && flying) {
flying = false;
}
}

private void snap_to_ground(Vector3 from) {
Expand All @@ -68,6 +78,16 @@ private void snap_to_ground(Vector3 from) {
}
}

private void flyControls(float delta) {
if (Input.IsActionPressed(Actions.movement_jump)) {
playerVelocity.y += jumpSpeed;
}

if (Input.IsActionPressed(Actions.movement_sneak)) {
playerVelocity.y -= jumpSpeed;
}
}

private void setMovementDir() {
forwardMove = 0;
rightMove = 0;
Expand All @@ -80,7 +100,7 @@ private void setMovementDir() {
}

private void queueJump() {
if (Input.IsActionJustPressed(Actions.movement_jump) && !wishJump && !Console.instance.isConsoleShown) {
if (Input.IsActionJustPressed(Actions.movement_jump) && !Console.instance.isConsoleShown) {
wishJump = true;
}

Expand Down Expand Up @@ -123,7 +143,12 @@ private void airMove(float delta) {
airControl(wishDir, wishSpeed2, delta);
}

playerVelocity.y -= gravity * delta;
if (wishJump) {
flying = true;
}
else {
playerVelocity.y -= gravity * delta;
}
}

private void airControl(Vector3 wishDir, float wishSpeed, float delta) {
Expand Down Expand Up @@ -195,7 +220,7 @@ private void applyFriction(float t, float delta) {
float speed = vec.Length();
var drop = 0.0f;

if (touchingGround) {
if (touchingGround || flying) {
var control = speed < runDeacceleration ? runDeacceleration : speed;
drop = control * friction * delta * t;
}
Expand Down
43 changes: 1 addition & 42 deletions test/Testing_Scene.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=7 format=2]

[ext_resource path="res://objects/HUD.tscn" type="PackedScene" id=1]
[ext_resource path="res://objects/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://scripts/renderer/ChunkRenderer.cs" type="Script" id=3]
[ext_resource path="res://scripts/world/ChunkHandler.cs" type="Script" id=4]

[sub_resource type="Environment" id=1]
background_mode = 1
Expand Down Expand Up @@ -33,45 +31,6 @@ extents = Vector3( 25, 0.01, 25 )

[node name="Testing_Scene" type="Spatial"]

[node name="Chunks" type="Node" parent="."]
script = ExtResource( 4 )

[node name="Chunk" type="MeshInstance" parent="Chunks"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, -5 )
script = ExtResource( 3 )

[node name="Chunk2" type="MeshInstance" parent="Chunks"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -21, 0, -5 )
script = ExtResource( 3 )

[node name="Chunk3" type="MeshInstance" parent="Chunks"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 11, 0, -5 )
script = ExtResource( 3 )

[node name="Chunk6" type="MeshInstance" parent="Chunks"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, -21 )
script = ExtResource( 3 )

[node name="Chunk5" type="MeshInstance" parent="Chunks"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -21, 0, -21 )
script = ExtResource( 3 )

[node name="Chunk4" type="MeshInstance" parent="Chunks"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 11, 0, -21 )
script = ExtResource( 3 )

[node name="Chunk9" type="MeshInstance" parent="Chunks"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, 11 )
script = ExtResource( 3 )

[node name="Chunk8" type="MeshInstance" parent="Chunks"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -21, 0, 11 )
script = ExtResource( 3 )

[node name="Chunk7" type="MeshInstance" parent="Chunks"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 11, 0, 11 )
script = ExtResource( 3 )

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 1 )

Expand Down

0 comments on commit 33433e6

Please sign in to comment.