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

PhantomCamera3D.set_third_person_rotation() rotates the camera around its own #399

Open
marinho opened this issue Oct 9, 2024 · 9 comments
Labels
3D Issues concerning 3D scenes enhancement New feature or request phantom camera Related to PhantomCamera nodes

Comments

@marinho
Copy link

marinho commented Oct 9, 2024

Issue description

For a PCam with follow_mode as ThirdPerson, I wrote this code expecting the camera to rotate around the target (which is the character object), but instead, this method is actually rotating the camera around its own Y.

const SPEED = 5

func _input(event):
	if event is InputEventMouseMotion:
		var x = event.relative.x * 0.001 * SPEED
		var old_rotation = %PCamThirdPerson.get_third_person_rotation()
		var new_rotation = Vector3(
			old_rotation.x,
			old_rotation.y + x,
			old_rotation.z
		)
		%PCamThirdPerson.set_third_person_rotation(new_rotation)

Steps to reproduce

  1. Add a CharacterBody3D, Camera3D, PCamHost and PCam to the scene, plus some ground with respective collisions
  2. Set PCam with:
    a. Priority = 0
    b. Follow Mode = Third Person
    c. Follow Target = CharacterBody3D
    d. Follow Offset = (0, 10, 10)
    e. Spring Length = 10
    f. Create a script and add the code I wrote above
    g. Run

(Optional) Minimal reproduction project

Additionally, if I set Look at Mode to Siple and Look at Target to CharacterBody3D (in face any other object), the camera will as well point to bottom with no clear reason.

Thanks!

@asvetin
Copy link

asvetin commented Jan 14, 2025

@marinho A bit late, but if you don't set the follow offset the rotation will work ( rotate around the point ).
That was my solution/fix

@ramokz
Copy link
Owner

ramokz commented Jan 14, 2025

Sorry, missed the initial post for this.

Yes, the offset effectively sets the position of the spring arm.
So if you change that, then you also change the point that it will orbit around.

@marinho
Copy link
Author

marinho commented Jan 15, 2025

thank you folks. I haven't worked on this project for a while, so, I must look back into it to recall if I made it to get it fixed anyhow. thank you again!

@ramokz
Copy link
Owner

ramokz commented Jan 16, 2025

I think this does raise the question of whether if there would be value in having the option to both offset the spring arm's point position and the camera itself relative to the spring arm's spring_length point. As opposed to just the former, like how it is currently.

@rohanrichards
Copy link

rohanrichards commented Feb 5, 2025

I think it's natural to want to offset a 3rd person camera while expecting it to orbit around the target's origin. This seems like the obvious use case for offsets. What is the recommended way to get the camera to sit back in a 3rd person position but still orbit the target origin? Just manually move the camera?

Edit: You can't just manually move the camera so I'm not sure how we're meant to do this, create a target node that is in the position we want?

Edit2: After having said that, it seemed really obvious. Maybe documentation or something to help a user get there faster? For future travelers, here's what I did:

Image

Image

@ramokz
Copy link
Owner

ramokz commented Feb 14, 2025

I would suspect being able to specific the offset of the coordinate the camera orbits would be the most basic want. Otherwise, you are reliant on the orbiting point being the exact center of the followed target, which I reckon is not always the desired outcome; e.g. when used on a humanoid-like character model.

So keeping that behavior as is, I think, is valid for the above reason, but also to align with the behavior of the other follow modes.

It shouldn't be much effort to add a secondary offset for this particular follow mode called, e.g., orbit offset that offsets the camera from the spring arm's end coordinate, which should give a bit more flexibility.

@ramokz ramokz added enhancement New feature or request phantom camera Related to PhantomCamera nodes 3D Issues concerning 3D scenes labels Feb 14, 2025
@troykinsella
Copy link

troykinsella commented Mar 2, 2025

Just chiming in that I've sort of worked around this issue by offsetting a follow target from desired rotation pivot to achieve the third person camera looking over the shoulder of the player, as noted above in @rohanrichards's edit #2. This maintains the right relative offset to the player regardless of camera orbit direction, which is good, but this approach still has the significant issue that with the follow target being outside of the player's collision shape, it can penetrate walls and objects. When it does so, the camera clips into and through walls, being that the origin of the spring arm is effectively already in the wall. That's my theory, but perhaps I'm missing something.

Thanks for the excellent add-on!

@rohanrichards
Copy link

rohanrichards commented Mar 2, 2025 via email

@troykinsella
Copy link

Just thinking out loud, but your follow target can be any node, so it could
have its own collider and it's own collision logic

Yeah, good thought. Also thinking out loud, my initial concern there is that the player can't touch the wall if the camera is pointing a certain direction, assuming the follow target offset is a static distance. Or, maybe the offset could itself be on a spring arm. Anyways, you triggered several experiment ideas to try out. Thanks @rohanrichards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3D Issues concerning 3D scenes enhancement New feature or request phantom camera Related to PhantomCamera nodes
Projects
None yet
Development

No branches or pull requests

5 participants