Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCamMouseFollow does not work! #9

Open
szabiszekely opened this issue Sep 30, 2024 · 1 comment
Open

PCamMouseFollow does not work! #9

szabiszekely opened this issue Sep 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@szabiszekely
Copy link

Describe the bug
Cannot add Mouse follow without crashing
To Reproduce
Add a PCamMouseFollow addon to a ProCam2D

Screenshots
image_2024-09-30_135306800

Desktop (please complete the following information):

  • OS: Windows
  • Godot Version 4.3
  • Plugin Version 1.0.0
@szabiszekely szabiszekely added the bug Something isn't working label Sep 30, 2024
@allendawodu
Copy link

allendawodu commented Nov 21, 2024

Instead of dividing by 2, divide by 2.0.

Here's an improved version of the script that includes damping (smoothing):

@tool
extends PCamAddon
class_name PCamMouseFollow

@export var max_offset := Vector2(300.0, 300.0)
@export_range(0, 1) var damping := 0.1
var actual_offset := Vector2.ZERO

func _init():
	stage = "pre_process"

func pre_process(camera, delta):
	if not enabled or camera._playing_cinematic:
		return

	var viewport = camera.get_viewport()
	var mouse_position = viewport.get_mouse_position() - viewport.size / 2.0
	var viewport_size = viewport.size / 2

	var desired_offset = Vector2(
		clamp(mouse_position.x / viewport_size.x, -1, 1) * max_offset.x,
		clamp(mouse_position.y / viewport_size.y, -1, 1) * max_offset.y
	)
	actual_offset = actual_offset.lerp(desired_offset, damping)

	# Add the calculated offset to the existing camera position
	camera._target_position += actual_offset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants