Skip to content

Commit

Permalink
0.7.1 (#314)
Browse files Browse the repository at this point in the history
* Move all spring arm initializaiton code out of _process into _ready (#282)

* Move all spring arm initializaiton code out of _process into _ready. Resolves #193

* Making _follow_spring_arm explicitly top_level

* Default _follow_spring_arm.position initialization to the original pcam position if follow_target is not available

* Updated plugin.cfg to 0.7.1

* Change Camera3DResource.cull_mask to use export_flags_3d_render. Resolves #290 (#293)

* Only show viewfinder if the active PCam's mode is framed (#295)

* Only show viewfinder in the correct follow mode

* Adjust comments

* Reorder early returns

* Remove unneeded type cast

* Updated Editor Updater wording for major releases

* Improved Limit Target error setter

* Added FUNDING.yml

* 2D Follow Physics Interpolation (#294)

* Initial _process / _physics_process logic split

* More 2d physics interpolation supported
- [Added] Interpolation Update Mode to PCamHost
- [Added] Additional warnings

* Commented out 4.3 specific code

* Stripped out a few todo comments

* Removed uneeded checkers

* Added physics body checker for Group Follow

* Added reset_physics_interpolation
- [Updated] Physics Interpolation to use string setters

* Added physics target checker to PCam3D
- [Moved] Follow Targets setters/getters closer to other Follow setters/getters

* Aligned PCam2D' script with PCam3D's

* Added missing variable assignment

* Added missing return for Framed Follow checker

* Removed unneeded boolean flag

* Tidied up process logic

* Added Jitter Tip output

* Added physics checker to Look At Group

* Updated parameter type from NodePath to Node3D

* Updated spacing for setters/getter functions

* Set _player_visual to top level in 2D example scene

* Added additional jitter context

* Updated append_look_at_targets_array

* Added Godot 4.3 2D example scene variants

---------

Co-authored-by: ZenithStar <ZenithStar@users.noreply.github.com>
Co-authored-by: audeck <55060124+audeck@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 1, 2024
1 parent d8a6e24 commit 0b2b1a9
Show file tree
Hide file tree
Showing 23 changed files with 5,051 additions and 410 deletions.
14 changes: 14 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: ramokz
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ visible = false

[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(107, -172.5)
zoom = Vector2(1.3375, 1.3375)
position_smoothing_speed = 8.0

[node name="PhantomCameraHost" type="Node" parent="Camera2D"]
Expand All @@ -631,7 +630,6 @@ script = ExtResource("6_diuy4")
priority = 10
follow_mode = 3
follow_targets = [NodePath("../GroupNPCSprite"), NodePath("../CharacterBody2D/PlayerVisuals")]
zoom = Vector2(1.3375, 1.3375)
tween_resource = SubResource("Resource_spy00")
tween_on_load = false
follow_damping = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,11 @@ position = Vector2(66, -50)

[node name="RoomLeftPhantomCamera2D" type="Node2D" parent="." node_paths=PackedStringArray("follow_target")]
unique_name_in_owner = true
position = Vector2(66, -113)
position = Vector2(66, -113.205)
script = ExtResource("4_4b648")
priority = 5
follow_mode = 2
follow_target = NodePath("../CharacterBody2D")
follow_target = NodePath("../CharacterBody2D/PlayerVisuals")
zoom = Vector2(2, 2)
tween_resource = SubResource("Resource_ct1eh")
follow_offset = Vector2(0, -63.205)
Expand Down Expand Up @@ -703,7 +703,7 @@ follow_damping = true
draw_limits = true

[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(66, -113)
position = Vector2(66, -113.205)
zoom = Vector2(2, 2)
limit_left = -387
limit_top = -528
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extends Node2D

@onready var pcam_room_left: PhantomCamera2D = %RoomLeftPhantomCamera2D
@onready var pcam_room_centre: PhantomCamera2D = %RoomCentrePhantomCamera2D
@onready var pcam_room_right: PhantomCamera2D = %RoomRightPhantomCamera2D

@onready var player: Node2D = %CharacterBody2D

@onready var area_2d_room_left: Area2D = %RoomLeftArea2D
@onready var area_2d_room_centre: Area2D = %RoomCentreArea2D
@onready var area_2d_room_right: Area2D = %RoomRightArea2D


func _ready():
pcam_room_left.set_follow_offset(Vector2(0, -80))
pcam_room_right.set_follow_offset(Vector2(0, -80))

area_2d_room_left.body_entered.connect(_on_body_entered.bind(pcam_room_left))
area_2d_room_centre.body_entered.connect(_on_body_entered.bind(pcam_room_centre))
area_2d_room_right.body_entered.connect(_on_body_entered.bind(pcam_room_right))

area_2d_room_left.body_exited.connect(_on_body_exited.bind(pcam_room_left))
area_2d_room_centre.body_exited.connect(_on_body_exited.bind(pcam_room_centre))
area_2d_room_right.body_exited.connect(_on_body_exited.bind(pcam_room_right))


func _on_body_entered(body: Node2D, pcam: PhantomCamera2D) -> void:
if body == player:
pcam.set_follow_target(player)
pcam.set_priority(20)


func _on_body_exited(body: Node2D, pcam: PhantomCamera2D) -> void:
if body == player:
pcam.set_priority(0)
pcam.set_follow_target(null)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var InputMovementDic: Dictionary = {
func _ready() -> void:
_player_area2d.connect("body_shape_entered", _show_prompt)
_player_area2d.connect("body_shape_exited", _hide_prompt)

_ui_sign = owner.get_node("%UISign")

for input in InputMovementDic:
Expand All @@ -61,6 +61,12 @@ func _ready() -> void:
InputMap.add_action(action_val)
InputMap.action_add_event(action_val, movement_input)

_player_visuals.top_level = true

if Engine.get_version_info().major == 4 and \
Engine.get_version_info().minor >= 3:
printerr("Please run the other 2D example scenes, in the 2D-4.3 directory, for more up-to-date example setups.")


func _unhandled_input(event: InputEvent) -> void:
if _is_interactive:
Expand Down Expand Up @@ -109,7 +115,6 @@ func _interactive_node_logic() -> void:


func _physics_process(delta: float) -> void:

_physics_body_trans_last = _physics_body_trans_current
_physics_body_trans_current = global_transform

Expand Down Expand Up @@ -143,7 +148,7 @@ func _process(delta) -> void:
_physics_body_trans_current,
Engine.get_physics_interpolation_fraction()
).origin


func _show_prompt(body_rid: RID, body: Node2D, body_shape_index: int, local_shape: int) -> void:
if body is TileMap:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
extends CharacterBody2D

@onready var _player_area2d = %PlayerArea2D
@onready var _player_visuals: Node2D = %PlayerVisuals
@onready var _player_sprite: Sprite2D = %PlayerSprite
@onready var _interaction_prompt: Panel = %InteractionPrompt
@onready var _ui_sign: Control
@onready var _dark_overlay: ColorRect = %DarkOverlay

const KEY_STRINGNAME: StringName = "Key"
const ACTION_STRINGNAME: StringName = "Action"
const INPUT_MOVE_LEFT_STRINGNAME: StringName = "move_left"
const INPUT_MOVE_RIGHT_STRINGNAME: StringName = "move_right"

const SPEED = 350.0
const JUMP_VELOCITY = -750.0

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity: int = 2400
var _is_interactive: bool
var _can_open_inventory: bool
var _movement_disabled: bool
var tween: Tween
var _interactive_UI: Control
var _active_pcam: PhantomCamera2D

enum InteractiveType {
NONE = 0,
ITEM = 1,
INVENTORY = 2,
}
var _interactive_object: InteractiveType = InteractiveType.NONE

var InputMovementDic: Dictionary = {
INPUT_MOVE_LEFT_STRINGNAME: {
KEY_STRINGNAME: KEY_A,
ACTION_STRINGNAME: INPUT_MOVE_LEFT_STRINGNAME
},
INPUT_MOVE_RIGHT_STRINGNAME: {
KEY_STRINGNAME: KEY_D,
ACTION_STRINGNAME: INPUT_MOVE_RIGHT_STRINGNAME
},
}


func _ready() -> void:
_player_area2d.connect("body_shape_entered", _show_prompt)
_player_area2d.connect("body_shape_exited", _hide_prompt)

_ui_sign = owner.get_node("%UISign")

for input in InputMovementDic:
var key_val = InputMovementDic[input].get(KEY_STRINGNAME)
var action_val = InputMovementDic[input].get(ACTION_STRINGNAME)

var movement_input = InputEventKey.new()
movement_input.physical_keycode = key_val
InputMap.add_action(action_val)
InputMap.action_add_event(action_val, movement_input)

if Engine.get_version_info().major == 4 and \
Engine.get_version_info().minor < 3:
printerr("This scene is designed to only work properly in Godot 4.3 or later that supports 2D Physics Interpolation.")
printerr("Please run the other 2D example scenes in the other directory.")


func _unhandled_input(event: InputEvent) -> void:
if _is_interactive:
if Input.is_physical_key_pressed(KEY_F):
if tween:
tween.kill()

if not _movement_disabled:
tween = get_tree().create_tween()

_movement_disabled = true
_active_pcam.set_priority(10)

_show_interactive_node(_interactive_UI)
_interactive_node_logic()

else:
_hide_interactive_node(_interactive_UI)
_interactive_node_logic()


if Input.is_physical_key_pressed(KEY_ESCAPE) and _movement_disabled:
_hide_interactive_node(_interactive_UI)
_interactive_node_logic()


func _show_interactive_node(UI: Control) -> void:
UI.modulate.a = 0
UI.visible = true
tween.tween_property(UI, "modulate", Color.WHITE, 1).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_CIRC)


func _hide_interactive_node(UI: Control) -> void:
_movement_disabled = false
_active_pcam.set_priority(0)
UI.visible = false


func _interactive_node_logic() -> void:
match _interactive_object:
2:
if _movement_disabled:
_dark_overlay.set_visible(true)
else:
_dark_overlay.set_visible(false)


func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity.y += gravity * delta

if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY

if _movement_disabled: return

var input_dir: = Input.get_axis(
INPUT_MOVE_LEFT_STRINGNAME,
INPUT_MOVE_RIGHT_STRINGNAME
)

if input_dir:
velocity.x = input_dir * SPEED
if input_dir > 0:
_player_sprite.set_flip_h(false)
elif input_dir < 0:
_player_sprite.set_flip_h(true)
else:
velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()


func _show_prompt(body_rid: RID, body: Node2D, body_shape_index: int, local_shape: int) -> void:
if body is TileMap:
var tile_map: TileMap = body

var tile_coords: Vector2i = tile_map.get_coords_for_body_rid(body_rid)
var cell_data: TileData = tile_map.get_cell_tile_data(1, tile_coords)

if cell_data:
var cell_data_type: StringName = cell_data.get_custom_data("Type")
# var cell_global_pos: Vector2 = tile_map.to_global(tile_map.map_to_local(tile_coords))
_is_interactive = true
_interaction_prompt.set_visible(true)

match cell_data_type:
"Sign":
_interactive_UI = owner.get_node("%UISign")
_active_pcam = %ItemFocusPhantomCamera2D
_interactive_object = InteractiveType.ITEM
"Inventory":
_interactive_UI = owner.get_node("%UIInventory")
_interactive_object = InteractiveType.INVENTORY
_active_pcam = %InventoryPhantomCamera2D


func _hide_prompt(body_rid: RID, body: Node2D, body_shape_index: int, local_shape: int) -> void:
if body is TileMap:
var tile_map: TileMap = body

var tile_coords: Vector2i = tile_map.get_coords_for_body_rid(body_rid)
var cell_data: TileData = tile_map.get_cell_tile_data(1, tile_coords)

if cell_data:
_interaction_prompt.set_visible(false)
_is_interactive = false
_interactive_UI = null
_interactive_object = InteractiveType.NONE
_active_pcam = null

Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ func _ready() -> void:
for input in InputMovementDic:
var key_val = InputMovementDic[input].get(KEY_STRINGNAME)
var action_val = InputMovementDic[input].get(ACTION_STRINGNAME)

_camera = owner.get_node("%MainCamera3D")

var movement_input = InputEventKey.new()
movement_input.physical_keycode = key_val
InputMap.add_action(action_val)
InputMap.action_add_event(action_val, movement_input)

_player_visual.top_level = true


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ theme_override_styles/pressed = SubResource("StyleBoxFlat_yn22d")
alignment = 1
item_count = 2
selected = 0
popup/item_0/text = "No"
popup/item_0/text = "Confirm choice"
popup/item_0/id = 0
popup/item_1/text = "Yes"
popup/item_1/text = "Yes, I am prepared"
popup/item_1/id = 1

[node name="DownloadButton" type="Button" parent="VBox/Center/VBoxContainer"]
Expand Down
2 changes: 1 addition & 1 deletion addons/phantom_camera/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="Phantom Camera"
description="Control the movement and dynamically tween 2D & 3D cameras positions. Built for Godot 4. Inspired by Cinemachine."
author="Marcus Skov"
version="0.7.0.6"
version="0.7.1"
script="plugin.gd"
5 changes: 5 additions & 0 deletions addons/phantom_camera/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func _enter_tree() -> void:
ProjectSettings.set_setting(updater_constants.setting_updater_notify_release, true)
ProjectSettings.set_initial_value(updater_constants.setting_updater_notify_release, true)

## Enables or disable
if not ProjectSettings.has_setting("phantom_camera/tips/show_jitter_tips"):
ProjectSettings.set_setting("phantom_camera/tips/show_jitter_tips", true)
ProjectSettings.set_initial_value("phantom_camera/tips/show_jitter_tips", true)

func btn_toggled(toggled_on: bool):
if toggled_on:
editor_panel_instance.viewfinder.viewfinder_visible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const setting_updater_name: StringName = setting_phantom_camera + "updater/"

# Updater Settings
const setting_updater_enabled: StringName = setting_updater_name + "enable_updater"
const setting_updater_notify_release: StringName = setting_updater_name + "show_new_release_info_on_editor_launch_in_output"
const setting_updater_notify_release: StringName = setting_updater_name + "show_new_release_info_on_editor_launch_in_output"
Loading

0 comments on commit 0b2b1a9

Please sign in to comment.