free bouncing with the floor

master
Sascha 2023-09-13 17:40:17 +07:00
parent dd16759950
commit c3f3beaa55
6 changed files with 56 additions and 18 deletions

@ -13,7 +13,13 @@ config_version=5
config/name="Evolution" config/name="Evolution"
run/main_scene="res://scenes/World.tscn" run/main_scene="res://scenes/World.tscn"
config/features=PackedStringArray("4.1", "C#", "Forward Plus") config/features=PackedStringArray("4.1", "C#", "Forward Plus")
config/icon="res://graphics/icon.svg" config/icon="res://graphics/Orange/texture_01.png"
[display]
window/size/viewport_width=1920
window/size/viewport_height=1024
window/size/mode=2
[dotnet] [dotnet]

@ -11,12 +11,12 @@ albedo_texture = ExtResource("1_kfglw")
[node name="OrangeBox" type="Node3D"] [node name="OrangeBox" type="Node3D"]
script = ExtResource("1_rm42w") script = ExtResource("1_rm42w")
[node name="OrangeBox" type="RigidBody3D" parent="."] [node name="OrangeBoxRigidBody3D" type="RigidBody3D" parent="."]
mass = 1.5 mass = 1.5
[node name="CollisionShapeBox" type="CollisionShape3D" parent="OrangeBox"] [node name="OrangeBoxCollisionShapeBox" type="CollisionShape3D" parent="OrangeBoxRigidBody3D"]
transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0, 0, 0) transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0, 0, 0)
shape = SubResource("BoxShape3D_6js7j") shape = SubResource("BoxShape3D_6js7j")
[node name="CSGBox" type="CSGBox3D" parent="OrangeBox/CollisionShapeBox"] [node name="OrangeBoxCSGBox" type="CSGBox3D" parent="OrangeBoxRigidBody3D/OrangeBoxCollisionShapeBox"]
material_override = SubResource("StandardMaterial3D_dsxvl") material_override = SubResource("StandardMaterial3D_dsxvl")

@ -1,7 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://bwn0di86nkots"] [gd_scene load_steps=6 format=3 uid="uid://bwn0di86nkots"]
[ext_resource type="Script" path="res://scripts/World.cs" id="1_2chdl"] [ext_resource type="Script" path="res://scripts/World.cs" id="1_2chdl"]
[ext_resource type="Texture2D" uid="uid://bw4vb1yfno12m" path="res://graphics/Light/texture_06.png" id="1_7bu66"] [ext_resource type="Texture2D" uid="uid://bw4vb1yfno12m" path="res://graphics/Light/texture_06.png" id="1_7bu66"]
[ext_resource type="Script" path="res://scripts/Floor.cs" id="3_q36sk"]
[sub_resource type="BoxShape3D" id="BoxShape3D_fl40q"]
size = Vector3(100, 0.1, 100)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_t4i04"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_t4i04"]
albedo_texture = ExtResource("1_7bu66") albedo_texture = ExtResource("1_7bu66")
@ -10,15 +14,24 @@ uv1_scale = Vector3(8, 8, 8)
[node name="World" type="Node3D"] [node name="World" type="Node3D"]
script = ExtResource("1_2chdl") script = ExtResource("1_2chdl")
[node name="Floor" type="CSGBox3D" parent="."]
transform = Transform3D(50, 0, 0, 0, 0.1, 0, 0, 0, 50, 0, 0, 0)
use_collision = true
material = SubResource("StandardMaterial3D_t4i04")
[node name="Camera3D" type="Camera3D" parent="."] [node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.925183, 0.379521, 0, -0.379521, 0.925183, 0, 14.6844, 32.8237) transform = Transform3D(1, 0, 0, 0, 0.925183, 0.379521, 0, -0.379521, 0.925183, 0, 24.4204, 48.4601)
fov = 90.0 fov = 120.0
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.826207, 0.563367, 0, -0.563367, 0.826206, 0, 14.8709, 19.8929) transform = Transform3D(1, 0, 0, 0, 0.826207, 0.563367, 0, -0.563367, 0.826206, 0, 14.8709, 19.8929)
shadow_enabled = true shadow_enabled = true
[node name="Floor" type="Node3D" parent="."]
script = ExtResource("3_q36sk")
[node name="FloorRigidBody3D" type="RigidBody3D" parent="Floor"]
mass = 1000.0
gravity_scale = 0.25
[node name="FloorCollisionShape3D" type="CollisionShape3D" parent="Floor/FloorRigidBody3D"]
shape = SubResource("BoxShape3D_fl40q")
[node name="FloorCSGBox3D" type="CSGBox3D" parent="Floor/FloorRigidBody3D/FloorCollisionShape3D"]
transform = Transform3D(100, 0, 0, 0, 0.1, 0, 0, 0, 100, 0, 0, 0)
material = SubResource("StandardMaterial3D_t4i04")

@ -3,11 +3,16 @@ using Godot;
namespace Evolution.scripts; namespace Evolution.scripts;
public partial class Box : Node3D { public partial class Box : Node3D {
private RigidBody3D rigidbody3d; private RigidBody3D rb;
public override void _Ready() => rigidbody3d = GetChild<RigidBody3D>(0); private Vector3 rotation;
private const int randomRange = 100;
public override void _Ready() {
rb = GetChild<RigidBody3D>(0);
rotation = new(GD.RandRange(-randomRange, randomRange), GD.RandRange(-randomRange, randomRange), GD.RandRange(-randomRange, randomRange));
}
public override void _Process(double delta) { public override void _Process(double delta) {
Vector3 rotation = new(GD.RandRange(-5, 5), GD.RandRange(-5, 5), GD.RandRange(-5, 5)); rb.AngularVelocity = rotation * (float)delta;
// rigidbody3d.Rotate(rotation, 0.1f); if (rb.Position.Y < -50) QueueFree(); //Clear all boxes outside
} }
} }

@ -0,0 +1,14 @@
using Godot;
namespace Evolution.scripts;
public partial class Floor : Node3D {
private RigidBody3D rb;
public override void _Ready() => rb = (RigidBody3D)FindChild("FloorRigidBody3D");
public override void _Process(double delta) {
if (Input.IsKeyPressed(Key.Space)) {
rb.ApplyImpulse(new(0, GD.RandRange(1000, 2000), 0));
}
}
}

@ -25,9 +25,9 @@ public partial class World : Node3D {
private void CreateNewBox() { private void CreateNewBox() {
Node newBox = boxScenes[GD.RandRange(0, boxScenes.Count - 1)].Instantiate(); Node newBox = boxScenes[GD.RandRange(0, boxScenes.Count - 1)].Instantiate();
RigidBody3D rb = newBox.GetChild<RigidBody3D>(0); RigidBody3D rb = newBox.GetChild<RigidBody3D>(0);
rb.Position = new(GD.RandRange(-25, 25), GD.RandRange(25, 50), GD.RandRange(-25, 25)); rb.Position = new(GD.RandRange(-50, 50), GD.RandRange(50, 100), GD.RandRange(-50, 50));
rb.Rotation = new(GD.RandRange(-30, 30), GD.RandRange(-30, 30), GD.RandRange(-30, 30)); rb.Rotation = new(GD.RandRange(-30, 30), GD.RandRange(-30, 30), GD.RandRange(-30, 30));
float mass =(float)GD.RandRange(0.1, 1); float mass =(float)GD.RandRange(0.1, 3);
rb.Mass = mass; rb.Mass = mass;
CollisionShape3D cs = rb.GetChild<CollisionShape3D>(0); CollisionShape3D cs = rb.GetChild<CollisionShape3D>(0);
cs.Scale = new(mass, mass, mass); cs.Scale = new(mass, mass, mass);