mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-05 15:30:07 +01:00
Convert physics test projects to 4.0
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
extends Camera
|
||||
extends Camera3D
|
||||
|
||||
|
||||
const ROTATION_COEFF = 0.02
|
||||
@@ -14,7 +14,7 @@ func _ready():
|
||||
func _unhandled_input(event):
|
||||
var mouse_button_event = event as InputEventMouseButton
|
||||
if mouse_button_event:
|
||||
if mouse_button_event.button_index == BUTTON_RIGHT:
|
||||
if mouse_button_event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
_rotation_enabled = mouse_button_event.pressed
|
||||
return
|
||||
|
||||
@@ -28,7 +28,7 @@ func _unhandled_input(event):
|
||||
|
||||
|
||||
func _initialize_pivot():
|
||||
_rotation_pivot = Spatial.new()
|
||||
_rotation_pivot = Node3D.new()
|
||||
var camera_parent = get_parent()
|
||||
camera_parent.add_child(_rotation_pivot)
|
||||
camera_parent.remove_child(self)
|
||||
|
||||
17
3d/physics_tests/utils/characterbody_physics.gd
Normal file
17
3d/physics_tests/utils/characterbody_physics.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
|
||||
@export var _stop_on_slopes = false
|
||||
@export var _use_snap = false
|
||||
|
||||
var _gravity = 20.0
|
||||
|
||||
func _physics_process(delta):
|
||||
if is_on_floor():
|
||||
floor_snap_length = 0.2
|
||||
else:
|
||||
motion_velocity += Vector3.DOWN * _gravity * delta
|
||||
floor_snap_length = 0.0
|
||||
|
||||
floor_stop_on_slope = _stop_on_slopes
|
||||
move_and_slide()
|
||||
@@ -7,7 +7,7 @@ var _entry_template
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
Log.connect("entry_logged", self, "_on_log_entry")
|
||||
Log.connect("entry_logged", Callable(self, "_on_log_entry"))
|
||||
|
||||
_entry_template = get_child(0) as Label
|
||||
remove_child(_entry_template)
|
||||
@@ -29,9 +29,9 @@ func _on_log_entry(message, type):
|
||||
|
||||
new_entry.set_text(message)
|
||||
if type == Log.LogType.ERROR:
|
||||
new_entry.modulate = Color.red
|
||||
new_entry.modulate = Color.RED
|
||||
else:
|
||||
new_entry.modulate = Color.white
|
||||
new_entry.modulate = Color.WHITE
|
||||
|
||||
if get_child_count() >= MAX_ENTRIES:
|
||||
var first_entry = get_child(0) as Label
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Control
|
||||
|
||||
|
||||
export(Vector3) var world_offset
|
||||
@export var world_offset = Vector3.ZERO
|
||||
|
||||
var _pos_offset
|
||||
var _attachment
|
||||
@@ -9,7 +9,7 @@ var _attachment
|
||||
|
||||
func _ready():
|
||||
_pos_offset = rect_position
|
||||
_attachment = get_parent() as Spatial
|
||||
_attachment = get_parent() as Node3D
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
@@ -20,7 +20,7 @@ func _process(_delta):
|
||||
if viewport == null:
|
||||
return
|
||||
|
||||
var camera = viewport.get_camera()
|
||||
var camera = viewport.get_camera_3d()
|
||||
if camera == null:
|
||||
return
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
extends KinematicBody
|
||||
|
||||
|
||||
export(bool) var _gravity_on_floor = true
|
||||
export(bool) var _stop_on_slopes = false
|
||||
export(bool) var _use_snap = false
|
||||
|
||||
var _gravity = 20.0
|
||||
var _velocity = Vector3.ZERO
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
var snap = Vector3.DOWN * 0.2
|
||||
if is_on_floor() and _gravity_on_floor:
|
||||
_velocity += Vector3.DOWN * _gravity * delta
|
||||
else:
|
||||
_velocity += Vector3.DOWN * _gravity * delta
|
||||
snap = Vector3.ZERO
|
||||
|
||||
if _use_snap:
|
||||
_velocity = move_and_slide_with_snap(_velocity, snap, Vector3.UP, _stop_on_slopes)
|
||||
else:
|
||||
_velocity = move_and_slide(_velocity, Vector3.UP, _stop_on_slopes)
|
||||
@@ -1,13 +1,13 @@
|
||||
extends Label
|
||||
|
||||
|
||||
var test_name setget _set_test_name
|
||||
var test_name = "":
|
||||
set(value):
|
||||
if (test_name != value):
|
||||
return
|
||||
test_name = value
|
||||
set_text("Test: %s" % test_name)
|
||||
|
||||
|
||||
func _ready():
|
||||
set_text("Select a test from the menu to start it")
|
||||
|
||||
|
||||
func _set_test_name(value):
|
||||
test_name = value
|
||||
set_text("Test: %s" % test_name)
|
||||
|
||||
@@ -44,7 +44,7 @@ func _add_popup(parent_popup, path, label):
|
||||
parent_popup.add_child(popup_menu)
|
||||
parent_popup.add_submenu_item(label, label)
|
||||
|
||||
popup_menu.connect("index_pressed", self, "_on_item_pressed", [popup_menu, path])
|
||||
popup_menu.connect("index_pressed", Callable(self, "_on_item_pressed"), [popup_menu, path])
|
||||
|
||||
return popup_menu
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
extends RigidBody
|
||||
extends RigidDynamicBody3D
|
||||
|
||||
|
||||
onready var _forward = - transform.basis.z
|
||||
onready var _collision_shape = $CollisionShape
|
||||
onready var _material = $CollisionShape/MeshInstance.get_surface_material(0)
|
||||
@onready var _forward = -transform.basis.z
|
||||
@onready var _collision_shape = $CollisionShape
|
||||
@onready var _material = $CollisionShape/MeshInstance3D.get_active_material(0)
|
||||
|
||||
var _dir = 1.0
|
||||
var _distance = 10.0
|
||||
@@ -13,11 +13,17 @@ var _gravity_impulse = 30.0
|
||||
var _is_on_floor = false
|
||||
|
||||
|
||||
func _ready():
|
||||
if not _material:
|
||||
_material = StandardMaterial3D.new()
|
||||
$CollisionShape/MeshInstance3D.set_surface_override_material(0, _material)
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
if _is_on_floor:
|
||||
_material.albedo_color = Color.white
|
||||
_material.albedo_color = Color.WHITE
|
||||
else:
|
||||
_material.albedo_color = Color.red
|
||||
_material.albedo_color = Color.RED
|
||||
|
||||
|
||||
func _integrate_forces(state):
|
||||
@@ -34,8 +40,8 @@ func _integrate_forces(state):
|
||||
|
||||
|
||||
func ground_check():
|
||||
var space_state = get_world().direct_space_state
|
||||
var shape = PhysicsShapeQueryParameters.new()
|
||||
var space_state = get_world_3d().direct_space_state
|
||||
var shape = PhysicsShapeQueryParameters3D.new()
|
||||
shape.transform = _collision_shape.global_transform
|
||||
shape.shape_rid = _collision_shape.shape.get_rid()
|
||||
shape.collision_mask = 2
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extends RigidBody
|
||||
extends RigidDynamicBody3D
|
||||
|
||||
|
||||
const MOUSE_DELTA_COEFFICIENT = 0.01
|
||||
@@ -16,7 +16,7 @@ func _ready():
|
||||
func _input(event):
|
||||
var mouse_event = event as InputEventMouseButton
|
||||
if mouse_event and not mouse_event.pressed:
|
||||
if mouse_event.button_index == BUTTON_LEFT:
|
||||
if mouse_event.button_index == MOUSE_BUTTON_LEFT:
|
||||
_picked = false
|
||||
|
||||
var mouse_motion = event as InputEventMouseMotion
|
||||
@@ -27,7 +27,7 @@ func _input(event):
|
||||
func _input_event(_viewport, event, _click_pos, _click_normal, _shape_idx):
|
||||
var mouse_event = event as InputEventMouseButton
|
||||
if mouse_event and mouse_event.pressed:
|
||||
if mouse_event.button_index == BUTTON_LEFT:
|
||||
if mouse_event.button_index == MOUSE_BUTTON_LEFT:
|
||||
_picked = true
|
||||
_mouse_pos = mouse_event.position
|
||||
_last_mouse_pos = _mouse_pos
|
||||
@@ -37,11 +37,11 @@ func _physics_process(delta):
|
||||
if _picked:
|
||||
var mouse_delta = _mouse_pos - _last_mouse_pos
|
||||
|
||||
var world_delta = Vector3.ZERO
|
||||
var world_delta := Vector3.ZERO
|
||||
world_delta.x = mouse_delta.x * MOUSE_DELTA_COEFFICIENT
|
||||
world_delta.y = -mouse_delta.y * MOUSE_DELTA_COEFFICIENT
|
||||
|
||||
var camera = get_viewport().get_camera()
|
||||
var camera = get_viewport().get_camera_3d()
|
||||
if camera:
|
||||
var camera_basis = camera.global_transform.basis
|
||||
world_delta = camera_basis * world_delta
|
||||
@@ -50,7 +50,7 @@ func _physics_process(delta):
|
||||
var fov_coefficient = camera.fov / 70.0
|
||||
world_delta *= CAMERA_DISTANCE_COEFFICIENT * camera_dist * fov_coefficient
|
||||
|
||||
if mode == MODE_STATIC:
|
||||
if freeze:
|
||||
global_transform.origin += world_delta
|
||||
else:
|
||||
linear_velocity = world_delta / delta
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
extends ScrollContainer
|
||||
|
||||
|
||||
export(bool) var auto_scroll = false setget set_auto_scroll
|
||||
@export var auto_scroll = false
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
if auto_scroll:
|
||||
var scrollbar = get_v_scrollbar()
|
||||
scrollbar.value = scrollbar.max_value
|
||||
|
||||
|
||||
func set_auto_scroll(value):
|
||||
auto_scroll = value
|
||||
|
||||
@@ -11,7 +11,7 @@ var _engine = PhysicsEngine.OTHER
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
pause_mode = Node.PAUSE_MODE_PROCESS
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
|
||||
get_tree().debug_collisions_hint = true
|
||||
|
||||
@@ -21,7 +21,7 @@ func _enter_tree():
|
||||
_engine = PhysicsEngine.BULLET
|
||||
"Bullet":
|
||||
_engine = PhysicsEngine.BULLET
|
||||
"GodotPhysics":
|
||||
"GodotPhysics3D":
|
||||
_engine = PhysicsEngine.GODOT_PHYSICS
|
||||
_:
|
||||
_engine = PhysicsEngine.OTHER
|
||||
@@ -29,7 +29,10 @@ func _enter_tree():
|
||||
|
||||
func _process(_delta):
|
||||
if Input.is_action_just_pressed("toggle_full_screen"):
|
||||
OS.window_fullscreen = not OS.window_fullscreen
|
||||
if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
||||
else:
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
||||
|
||||
if Input.is_action_just_pressed("toggle_debug_collision"):
|
||||
var debug_collision_enabled = not _is_debug_collision_enabled()
|
||||
|
||||
Reference in New Issue
Block a user