diff --git a/Ball/bal213C.tmp b/Ball/bal213C.tmp new file mode 100644 index 0000000..e33143e --- /dev/null +++ b/Ball/bal213C.tmp @@ -0,0 +1,71 @@ +[gd_scene load_steps=11 format=3 uid="uid://dd1e3u5cyy3mk"] + +[ext_resource type="Material" uid="uid://ccktnp41cys0r" path="res://Ball/Meshes/ball_material.tres" id="1_5n3i6"] +[ext_resource type="Script" path="res://Ball/ball_test.gd" id="1_s3xmr"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_jblqj"] +radius = 0.1 + +[sub_resource type="SphereMesh" id="SphereMesh_52mtx"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_862wy"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_dwt7q"] + +[sub_resource type="BoxMesh" id="BoxMesh_1auv0"] + +[sub_resource type="SphereMesh" id="SphereMesh_xquva"] +radius = 0.2 +height = 0.4 + +[sub_resource type="SphereMesh" id="SphereMesh_bnhf3"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5h0ki"] +transparency = 1 +albedo_color = Color(1, 0.372549, 1, 0.701961) + +[node name="BallBase" type="RigidBody3D"] +collision_layer = 0 +collision_mask = 0 +gravity_scale = 0.0 +continuous_cd = true +lock_rotation = true +linear_damp_mode = 1 +angular_damp_mode = 1 +script = ExtResource("1_s3xmr") +speed = 20.0 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("SphereShape3D_jblqj") + +[node name="BallMesh" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.0029127) +mesh = SubResource("SphereMesh_52mtx") +surface_material_override/0 = ExtResource("1_5n3i6") + +[node name="BallBody" type="StaticBody3D" parent="."] +collision_layer = 4 +collision_mask = 5 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="BallBody"] +shape = SubResource("SphereShape3D_862wy") + +[node name="AnchorBody3D" type="StaticBody3D" parent="."] +top_level = true +collision_layer = 4 +collision_mask = 5 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="AnchorBody3D"] +shape = SubResource("SphereShape3D_dwt7q") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="AnchorBody3D"] +mesh = SubResource("BoxMesh_1auv0") + +[node name="TestMesh" type="MeshInstance3D" parent="."] +visible = false +mesh = SubResource("SphereMesh_xquva") + +[node name="TestMesh2" type="MeshInstance3D" parent="."] +visible = false +mesh = SubResource("SphereMesh_bnhf3") +surface_material_override/0 = SubResource("StandardMaterial3D_5h0ki") diff --git a/Ball/balE32A.tmp b/Ball/balE32A.tmp new file mode 100644 index 0000000..e33143e --- /dev/null +++ b/Ball/balE32A.tmp @@ -0,0 +1,71 @@ +[gd_scene load_steps=11 format=3 uid="uid://dd1e3u5cyy3mk"] + +[ext_resource type="Material" uid="uid://ccktnp41cys0r" path="res://Ball/Meshes/ball_material.tres" id="1_5n3i6"] +[ext_resource type="Script" path="res://Ball/ball_test.gd" id="1_s3xmr"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_jblqj"] +radius = 0.1 + +[sub_resource type="SphereMesh" id="SphereMesh_52mtx"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_862wy"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_dwt7q"] + +[sub_resource type="BoxMesh" id="BoxMesh_1auv0"] + +[sub_resource type="SphereMesh" id="SphereMesh_xquva"] +radius = 0.2 +height = 0.4 + +[sub_resource type="SphereMesh" id="SphereMesh_bnhf3"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5h0ki"] +transparency = 1 +albedo_color = Color(1, 0.372549, 1, 0.701961) + +[node name="BallBase" type="RigidBody3D"] +collision_layer = 0 +collision_mask = 0 +gravity_scale = 0.0 +continuous_cd = true +lock_rotation = true +linear_damp_mode = 1 +angular_damp_mode = 1 +script = ExtResource("1_s3xmr") +speed = 20.0 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("SphereShape3D_jblqj") + +[node name="BallMesh" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.0029127) +mesh = SubResource("SphereMesh_52mtx") +surface_material_override/0 = ExtResource("1_5n3i6") + +[node name="BallBody" type="StaticBody3D" parent="."] +collision_layer = 4 +collision_mask = 5 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="BallBody"] +shape = SubResource("SphereShape3D_862wy") + +[node name="AnchorBody3D" type="StaticBody3D" parent="."] +top_level = true +collision_layer = 4 +collision_mask = 5 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="AnchorBody3D"] +shape = SubResource("SphereShape3D_dwt7q") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="AnchorBody3D"] +mesh = SubResource("BoxMesh_1auv0") + +[node name="TestMesh" type="MeshInstance3D" parent="."] +visible = false +mesh = SubResource("SphereMesh_xquva") + +[node name="TestMesh2" type="MeshInstance3D" parent="."] +visible = false +mesh = SubResource("SphereMesh_bnhf3") +surface_material_override/0 = SubResource("StandardMaterial3D_5h0ki") diff --git a/Ball/ball_test.gd b/Ball/ball_test.gd new file mode 100644 index 0000000..368338e --- /dev/null +++ b/Ball/ball_test.gd @@ -0,0 +1,43 @@ +extends RigidBody3D + +@onready var mesh = $BallMesh +@onready var body = $BallBody +@onready var body_anchor = $AnchorBody + +@export var speed : float +@export var gravity : Vector3 +@export var stiffness : float + + +func _ready(): + linear_velocity = linear_velocity.normalized() * speed + DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) + +func _physics_process(delta): + if global_position.length() >= 100: + print("ball escaped") + queue_free() + + # Visual + var collision : KinematicCollision3D = body.move_and_collide(linear_velocity * delta, true) + if collision: + var collision_position = collision.get_position() + mesh.look_at(collision_position, Vector3.UP) + + if collision.get_collider().owner.is_in_group("balls"): + mesh.scale.z = (global_position - collision.get_collider().global_position).length() + else: + mesh.scale.z = (collision_position - global_position).length() * 2 + var scalexy = clamp(sqrt(1 / mesh.scale.z), 0.0, 2.0) + mesh.scale.x = scalexy + mesh.scale.y = scalexy + else: + mesh.scale = Vector3.ONE + + # Physics + body_anchor.velocity = (global_position - body_anchor.global_position).normalized() * speed + if not body_anchor.move_and_slide(): + body_anchor.global_position = global_position + + constant_force = gravity + (body_anchor.global_position - global_position) * stiffness * pow(speed, 2) + linear_velocity = linear_velocity.normalized() * clamp(linear_velocity.length(), 0, speed) diff --git a/Ball/ball_test.tscn b/Ball/ball_test.tscn new file mode 100644 index 0000000..abd0398 --- /dev/null +++ b/Ball/ball_test.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=7 format=3 uid="uid://dd1e3u5cyy3mk"] + +[ext_resource type="Material" uid="uid://ccktnp41cys0r" path="res://Ball/Meshes/ball_material.tres" id="1_5n3i6"] +[ext_resource type="Script" path="res://Ball/ball_test.gd" id="1_s3xmr"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_jblqj"] +radius = 0.1 + +[sub_resource type="SphereMesh" id="SphereMesh_52mtx"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_862wy"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_dwt7q"] + +[node name="BallBase" type="RigidBody3D" groups=["balls"]] +collision_layer = 0 +collision_mask = 0 +gravity_scale = 0.0 +lock_rotation = true +linear_damp_mode = 1 +angular_damp_mode = 1 +script = ExtResource("1_s3xmr") +speed = 10.0 +gravity = Vector3(0, -10, 0) +stiffness = 10.0 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("SphereShape3D_jblqj") + +[node name="BallMesh" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.0029127) +mesh = SubResource("SphereMesh_52mtx") +surface_material_override/0 = ExtResource("1_5n3i6") + +[node name="BallBody" type="StaticBody3D" parent="."] +collision_layer = 4 +collision_mask = 5 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="BallBody"] +shape = SubResource("SphereShape3D_862wy") + +[node name="AnchorBody" type="CharacterBody3D" parent="."] +top_level = true +collision_layer = 8 +collision_mask = 9 +motion_mode = 1 +wall_min_slide_angle = 0.0 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="AnchorBody"] +shape = SubResource("SphereShape3D_dwt7q") diff --git a/Player/player.gd b/Player/player.gd index 0616990..3676080 100644 --- a/Player/player.gd +++ b/Player/player.gd @@ -1,7 +1,7 @@ extends CharacterBody3D -const SPEED = 5.0 +const SPEED = 50.0 const JUMP_VELOCITY = 4.5 # Get the gravity from the project settings to be synced with RigidBody nodes. diff --git a/Player/player.tscn b/Player/player.tscn index 125f987..254a418 100644 --- a/Player/player.tscn +++ b/Player/player.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://Player/player.gd" id="1_f70jf"] [ext_resource type="Script" path="res://Player/player_camera_basis.gd" id="2_o7m3c"] [ext_resource type="Script" path="res://Player/shooter.gd" id="3_eijnn"] -[ext_resource type="PackedScene" uid="uid://rdlvlyf0l1l" path="res://Ball/ball.tscn" id="4_5tvf6"] +[ext_resource type="PackedScene" uid="uid://dd1e3u5cyy3mk" path="res://Ball/ball_test.tscn" id="4_rdfyn"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_v066f"] radius = 0.35 @@ -31,4 +31,4 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1) [node name="Shooter" type="Node3D" parent="Camera"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.5) script = ExtResource("3_eijnn") -ball_scene = ExtResource("4_5tvf6") +ball_scene = ExtResource("4_rdfyn") diff --git a/Player/shooter.gd b/Player/shooter.gd index 0c43b33..cdab9d6 100644 --- a/Player/shooter.gd +++ b/Player/shooter.gd @@ -2,9 +2,12 @@ extends Node3D @export var ball_scene : PackedScene +var count = 0 func shoot(spawn_position ,direction = Vector3.FORWARD, strength = 7): + count += 1 + print(count) var ball = ball_scene.instantiate() ball.linear_velocity = direction * strength diff --git a/World/world.tscn b/World/world.tscn index 2b55ddb..47bd979 100644 --- a/World/world.tscn +++ b/World/world.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=10 format=3 uid="uid://b06nx3ofndgjy"] +[gd_scene load_steps=11 format=3 uid="uid://b06nx3ofndgjy"] [ext_resource type="Texture2D" uid="uid://onahsd5he406" path="res://Misc/64x64_orange_grey.png" id="1_k0u6d"] [ext_resource type="PackedScene" uid="uid://ggl4tqcb5dbc" path="res://Player/player.tscn" id="1_n0nhi"] [ext_resource type="Script" path="res://Misc/debug_cone.gd" id="3_nsiny"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_bwr1w"] +albedo_color = Color(1, 1, 1, 0.882353) albedo_texture = ExtResource("1_k0u6d") uv1_scale = Vector3(0.5, 0.5, 0.5) uv1_triplanar = true @@ -20,6 +21,10 @@ points = PackedVector3Array(1.5, 0, 4, -1.5, 0, 4, 1.5, 0, -4, -1.5, 0, -4) radius = 3.0 height = 6.0 +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_587aa"] +transparency = 1 +albedo_color = Color(0.619608, 1, 0.67451, 0.678431) + [sub_resource type="SphereShape3D" id="SphereShape3D_hjh1m"] radius = 3.0 @@ -54,10 +59,11 @@ transform = Transform3D(0.707107, 0.707107, -3.09086e-08, 0, -4.37114e-08, -1, - shape = SubResource("ConvexPolygonShape3D_iauoa") [node name="Sphere" type="StaticBody3D" parent="Level"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, -6) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.736659, 2.85172, -3.29585) [node name="MeshInstance3D" type="MeshInstance3D" parent="Level/Sphere"] mesh = SubResource("SphereMesh_0a0pq") +surface_material_override/0 = SubResource("StandardMaterial3D_587aa") [node name="CollisionShape3D" type="CollisionShape3D" parent="Level/Sphere"] shape = SubResource("SphereShape3D_hjh1m") diff --git a/project.godot b/project.godot index 1491771..0935684 100644 --- a/project.godot +++ b/project.godot @@ -54,3 +54,4 @@ shoot={ 3d_physics/layer_1="general" 3d_physics/layer_2="player" 3d_physics/layer_3="balls" +3d_physics/layer_4="anchors"