Skip to content

Commit

Permalink
Test 2D physics interpolation pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinou committed Jul 3, 2023
1 parent 18bf079 commit 46e7b4b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 66 deletions.
6 changes: 3 additions & 3 deletions addons/smoothing/smoothing_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func _SetProcessing():

set_process(bEnable)
set_physics_process(bEnable)

set_as_toplevel(_TestFlags(SF_GLOBAL_OUT))


Expand Down Expand Up @@ -160,7 +160,7 @@ func _RefreshTransform():

func _FindTarget():
_m_Target = null

# If no target has been assigned in the property,
# default to using the parent as the target.
if target.is_empty():
Expand Down Expand Up @@ -203,7 +203,7 @@ func _process(_delta):
# We can always use local position rather than set_global_position
# because even in global mode we are set_as_top_level, and the result
# will be the same.

# translate
if _TestFlags(SF_TRANSLATE):
set_position(m_Pos_prev.linear_interpolate(m_Pos_curr, f))
Expand Down
13 changes: 4 additions & 9 deletions data/scenes/actors/grunt.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=10 format=2]

[ext_resource path="res://data/scripts/actors/grunt.gd" type="Script" id=1]
[ext_resource path="res://data/textures/grunt.png" type="Texture" id=2]
[ext_resource path="res://addons/smoothing/smoothing_2d.gd" type="Script" id=3]

[sub_resource type="PhysicsMaterial" id=1]
friction = 0.0
Expand All @@ -18,7 +17,7 @@ length = 1.5
loop = true
step = 0.25
tracks/0/type = "value"
tracks/0/path = NodePath("Smoothing2D/Sprite:frame")
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
Expand Down Expand Up @@ -71,12 +70,7 @@ step = 1.0
value = 1.0
percent_visible = false

[node name="Smoothing2D" type="Node2D" parent="."]
script = ExtResource( 3 )
target = NodePath("..")
flags = 35

[node name="Sprite" type="Sprite" parent="Smoothing2D"]
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 2 )
hframes = 4
frame = 3
Expand All @@ -90,6 +84,7 @@ shape = SubResource( 7 )
[node name="Timer" type="Timer" parent="."]
wait_time = 0.01
one_shot = true

[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_AnimationPlayer_finished"]
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_enter"]
[connection signal="body_exited" from="Area2D" to="." method="_on_Area2D_body_exit"]
25 changes: 10 additions & 15 deletions data/scenes/actors/player.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[gd_scene load_steps=17 format=2]
[gd_scene load_steps=16 format=2]

[ext_resource path="res://data/scripts/actors/player.gd" type="Script" id=1]
[ext_resource path="res://data/textures/player.png" type="Texture" id=2]
[ext_resource path="res://icon.png" type="Texture" id=3]
[ext_resource path="res://data/textures/circle.png" type="Texture" id=4]
[ext_resource path="res://addons/smoothing/smoothing_2d.gd" type="Script" id=5]
[ext_resource path="res://data/textures/crosshair.png" type="Texture" id=6]
[ext_resource path="res://data/scenes/actors/player_crosshair_color_gradient.tres" type="Gradient" id=7]

Expand All @@ -26,7 +25,7 @@ colors = PoolColorArray( 0, 1, 1, 0, 0, 1, 1, 1, 0.03125, 0, 1, 0 )
resource_name = "pain"
length = 0.3
tracks/0/type = "value"
tracks/0/path = NodePath("../Smoothing2D/Sprite:frame")
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
Expand All @@ -43,7 +42,7 @@ resource_name = "shoot"
length = 0.25
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("../Smoothing2D/Sprite:frame")
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
Expand All @@ -59,7 +58,7 @@ tracks/0/keys = {
loop = true
step = 0.25
tracks/0/type = "value"
tracks/0/path = NodePath("../Smoothing2D/Sprite:frame")
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
Expand All @@ -84,23 +83,19 @@ __meta__ = {
"__editor_plugin_screen__": "Script"
}

[node name="Smoothing2D" type="Node2D" parent="."]
script = ExtResource( 5 )
target = NodePath("../Player")

[node name="Sprite" type="Sprite" parent="Smoothing2D"]
position = Vector2( 0, -32 )
texture = ExtResource( 2 )
flip_h = true
hframes = 7

[node name="Player" type="RigidBody2D" parent="."]
collision_layer = 2
collision_mask = 7
mode = 2
physics_material_override = SubResource( 1 )
can_sleep = false

[node name="Sprite" type="Sprite" parent="Player"]
position = Vector2( 0, -32 )
texture = ExtResource( 2 )
flip_h = true
hframes = 7

[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"]
position = Vector2( 0, -32 )
shape = SubResource( 2 )
Expand Down
40 changes: 18 additions & 22 deletions data/scenes/misc/bullet.tscn
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=6 format=2]

[ext_resource path="res://data/scripts/misc/bullet.gd" type="Script" id=1]
[ext_resource path="res://data/textures/circle.png" type="Texture" id=2]
[ext_resource path="res://data/textures/light.png" type="Texture" id=3]
[ext_resource path="res://addons/smoothing/smoothing_2d.gd" type="Script" id=4]

[sub_resource type="Curve" id=1]
_data = [ Vector2( 0, 1 ), 0.0, -1.0, 0, 1, Vector2( 1, 0 ), -1.0, 0.0, 1, 0 ]

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 4, 4 )

[sub_resource type="Curve" id=1]
_data = [ Vector2( 0, 1 ), 0.0, -1.0, 0, 1, Vector2( 1, 0 ), -1.0, 0.0, 1, 0 ]

[node name="Bullet" type="Node2D"]
script = ExtResource( 1 )
__meta__ = {
"__editor_plugin_screen__": "2D"
}

[node name="Smoothing2D" type="Node2D" parent="."]
script = ExtResource( 4 )
target = NodePath("../RigidBody2D")

[node name="CPUParticles2D" type="CPUParticles2D" parent="Smoothing2D"]
amount = 50
local_coords = false
texture = ExtResource( 2 )
scale_amount = 0.02
scale_amount_curve = SubResource( 1 )

[node name="Light2D" type="Light2D" parent="Smoothing2D"]
texture = ExtResource( 3 )
color = Color( 1, 0.941176, 0.784314, 1 )
energy = 2.5

[node name="RigidBody2D" type="RigidBody2D" parent="."]
collision_layer = 8
collision_mask = 5
gravity_scale = 0.0
continuous_cd = 2
continuous_cd = 1
contacts_reported = 2
contact_monitor = true
can_sleep = false

[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
shape = SubResource( 2 )

[node name="CPUParticles2D" type="CPUParticles2D" parent="RigidBody2D"]
amount = 50
local_coords = false
texture = ExtResource( 2 )
scale_amount = 0.02
scale_amount_curve = SubResource( 1 )

[node name="Light2D" type="Light2D" parent="RigidBody2D"]
texture = ExtResource( 3 )
color = Color( 1, 0.941176, 0.784314, 1 )
energy = 2.5

[node name="Timer" type="Timer" parent="."]
wait_time = 3.0
one_shot = true
autostart = true

[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
4 changes: 2 additions & 2 deletions data/scripts/actors/grunt.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func _physics_process(delta: float) -> void:
return
if difference > 0:
linear_velocity = Vector2(-MAX_SPEED * delta, linear_velocity.y)
$"Smoothing2D/Sprite".flip_h = false
$"Sprite".flip_h = false
else:
linear_velocity = Vector2(MAX_SPEED * delta, linear_velocity.y)
$"Smoothing2D/Sprite".flip_h = true
$"Sprite".flip_h = true


func damage(dmg: int) -> void:
Expand Down
10 changes: 5 additions & 5 deletions data/scripts/actors/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
extends Node2D

# Maximum per-frame acceleration when running.
const ACCELERATION = 3000 * 60
const ACCELERATION = 3000 * 20

# Jump speed (velocity set when jumping)
const JUMP_SPEED = 350 * 60
const JUMP_SPEED = 350 * 20

# Jetpack speed
const JETPACK_SPEED = 17.5 * 60
Expand Down Expand Up @@ -55,7 +55,7 @@ onready var previous_position := player.position
onready var camera := $Player/Camera2D as Camera2D
onready var default_zoom := camera.zoom
onready var crosshair := $Crosshair as Sprite
onready var player_sprite := $Smoothing2D/Sprite as Sprite
onready var player_sprite := $Player/Sprite as Sprite
onready var preloader := $ResourcePreloader as ResourcePreloader
onready var animation_player := $Player/AnimationPlayer as AnimationPlayer
onready var crosshair_color_gradient := preloader.get_resource("crosshair_color_gradient") as Gradient
Expand Down Expand Up @@ -130,7 +130,7 @@ func _physics_process(delta) -> void:

# Flip player sprite if the crosshair is at the right of the player (player faces right),
# else don't flip it (player faces left).
$"Smoothing2D/Sprite".flip_h = crosshair_position.x > player.position.x
$"Player/Sprite".flip_h = crosshair_position.x > player.position.x

$"Player/JetpackParticles".emitting = using_jetpack

Expand Down Expand Up @@ -165,7 +165,7 @@ func _physics_process(delta) -> void:
var movement := Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
speed += ACCELERATION * movement * delta
# Apply Doom-style constant friction.
speed *= 0.85
speed *= 0.65

# Set the new velocity.
player.linear_velocity = Vector2(speed * delta, velocity.y)
Expand Down
4 changes: 2 additions & 2 deletions data/scripts/misc/bullet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func _on_Timer_timeout() -> void:
queue_free()
# Only make it stop emitting
else:
$"Smoothing2D/CPUParticles2D".emitting = false
$"Smoothing2D/Light2D".enabled = false
$"RigidBody2D/CPUParticles2D".emitting = false
$"RigidBody2D/Light2D".enabled = false
$Timer.wait_time = 2
$Timer.start()
kill = true
14 changes: 6 additions & 8 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ window/dpi/allow_hidpi=true
window/stretch/mode="2d"
window/stretch/aspect="expand"

[editor_plugins]

enabled=PoolStringArray( "smoothing" )

[image_loader]

filter=false
Expand All @@ -63,7 +59,7 @@ texture={

attack={
"deadzone": 0.5,
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"doubleclick":false,"script":null)
]
}
jetpack={
Expand Down Expand Up @@ -121,18 +117,18 @@ toggle_hud={
}
use={
"deadzone": 0.5,
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null)
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"doubleclick":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":69,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
weapon_next={
"deadzone": 0.5,
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null)
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"canceled":false,"pressed":false,"doubleclick":false,"script":null)
]
}
weapon_previous={
"deadzone": 0.5,
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":4,"pressed":false,"doubleclick":false,"script":null)
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"doubleclick":false,"script":null)
]
}
zoom_in={
Expand Down Expand Up @@ -175,8 +171,10 @@ locale_filter=[ 0, [ ] ]

[physics]

common/physics_fps=20
common/physics_jitter_fix=0.0
2d/default_gravity=800
common/physics_interpolation=true

[rendering]

Expand Down

0 comments on commit 46e7b4b

Please sign in to comment.