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

Scripted player camera #1215

Closed
wants to merge 1 commit into from

Conversation

MirceaKitsune
Copy link
Contributor

I have created a Lua function which allows scripting the player's camera. You specify a position offset, rotation offset, FOV multiplier, and transition time. Additionally you can specify whether that's a third person viewpoint, in which case the wielded item is hidden and the player can see their own model.

One practical use is allowing players of different sizes to have a correct eye position... so a server can offer both giant and midget player models, while this makes it possible to define a proper camera height for each. Another is vehicles, which can now setup a behind view like any racing game when entered. Also beds, for which you can offset the location and rotation of the camera to make it look like you're laying down. It can also be used to change the FOV as an effect for specific actions... like being underwater or running. Many more uses can probably be found.

Note that this might invalidate existing "third person camera" patches, as it adds the ability to have a 3rd person camera but with a lot more features... no harm meant to the authors of those patches, since a choice between this and them might have to be taken. Also note that the local player model is still networked and will visually lag like any player on the server, which can probably be fixed later.

@MirceaKitsune
Copy link
Contributor Author

I discussed this on IRC and spoke with BlockMen. We agreed there are advantages and disadvantages in both my code and his. Mine allows setting camera position and rotation via Lua, but makes the server responsible with switching between 1st / 3rd person views which I agree isn't normal and should be client-side. There's also no detection of solid objects... my third person cameras would go into walls and not stick against the surface.

I asked him to add Lua offsets for both 1st and 3rd person views... something like player:set_camera_offset({1st_person_position}, {3rd_person_position}). Once that's in, we might later look into another function to attach the camera to entities other than the player... to make CCTV cameras / turrets / remote-controlled vehicles / mind controlled mobs possible.

So for now at least, I'm pausing this code. Watch #1114 and we'll see how it goes there :)

@4aiman
Copy link
Contributor

4aiman commented Apr 11, 2014

@MirceaKitsune:
quote: "but makes the server responsible ... which I agree isn't normal"
But server-controlled camera may be the key to prevent cheating. Especially with free-to-controll camera. TMM some way to disable camera movement too far (may be to unloaded areas) should be represented.
Not as the 1st thing to do, just to be more polished and to get rid of possible future problems, like camera attached to a mob that has moved to an unloaded area and got unloaded too. What would be with the camera?

@MirceaKitsune
Copy link
Contributor Author

@4aiman Problem is, it's not normal for the server to toggle between 1st person and 3rd person views. Server admins could restrict the camera, and you'd also wait for the server response when toggling. However, the server should be in control of camera positions via a per-player Lua function, which is what I spoke to BlockMen about adding. If Lua specifies the offset for both 1st and 3rd person cameras, and the client only toggles between the two using those vectors, everyone is happy.

When support for attaching cameras to entities comes (after BlockMen's code is in), some things must be considered. Obviously the camera can only be attached to an entity or node that's loaded client-side. If the local entity disappears, the camera must of course be detached and returned to normal. The only thing that can be done to avoid this is using 'forced world loading', so entities with a player's camera on them load and generate the world like the presence of a player does.

@4aiman
Copy link
Contributor

4aiman commented Apr 12, 2014

@MirceaKitsune I only asked that to hear out your point of view on server controllable camera.
And of course I agree with you on the point that toggling by a server isn't nice.
What kind of control you think a server should impose on a camera?

Also, when finished to some extent, it may be useful to add smth like hudset(HUD_group_id,on_or_off_state) function to toggle groups of HUDs w/o extra code.
It could be easily done in lua right now, but is pointless ATM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants