Page 1 of 1

Scripted player camera

PostPosted: Thu Apr 10, 2014 16:06
by MirceaKitsune
Thread for pull #1215

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.

PostPosted: Thu Apr 10, 2014 16:12
by Sokomine
MirceaKitsune wrote:One practical use is allowing players of different sizes to have a correct eye position.

That sounds fine, especially in combination with riding on animals/using vehicles. Also a position behind the vehicle sounds very intresting!

MirceaKitsune wrote: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.

That's also a problem when you try to follow another player: There are just not enough updates. I've even considered writing a mod that allows to auto-follow someone who tries to lead you to his house...

Hope your patch gets merged.

PostPosted: Thu Apr 10, 2014 17:27
by Inocudom
This sounds like a promising prospect, MirceaKitsune. It is a shame that we don't see you around here more often.

PostPosted: Thu Apr 10, 2014 18:00
by MirceaKitsune
Inocudom wrote:This sounds like a promising prospect, MirceaKitsune. It is a shame that we don't see you around here more often.


Thanks. I'm always around, just more or less active at times. Don't think I'd ever leave Minetest ^^

PostPosted: Thu Apr 10, 2014 18:17
by hoodedice
Can this be attached to *just* in front of the player model's head, and then the model be displayed at all times?

PostPosted: Thu Apr 10, 2014 20:27
by MirceaKitsune
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 this thread and we'll see how it goes there :)

PostPosted: Fri Apr 11, 2014 01:29
by Evergreen
This would be great for cinematics. Like running a camera between two points.

PostPosted: Fri Apr 11, 2014 05:16
by paramat
Sounds good, lots of potential.

PostPosted: Fri Apr 11, 2014 07:50
by 4aiman
Great addition! Is there any doc available?

MirceaKitsune wrote: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.

Does it lags more with this patch then without? (With Blockmen's version it does.)

PostPosted: Fri Apr 11, 2014 09:25
by hoodedice
4aiman wrote:Great addition! Is there any doc available?

MirceaKitsune wrote: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.

Does it lags more with this patch then without? (With Blockmen's version it does.)


I would think so.

Also, what are your specs? My skeleton system runs BlockMen's 3D view with no lag.

PostPosted: Fri Apr 11, 2014 11:53
by MirceaKitsune
Evergreen wrote:This would be great for cinematics. Like running a camera between two points.


With the approach in BlockMen's branch, the concept of "a 1st person camera and a 3rd person camera" would be hard coded, although Lua sets the positions for both. Cinematic views could somewhat be done by having nodes offset the 3rd person camera only, so the player only sees the effect while he chooses out-of-body view locally.

4aiman wrote:Great addition! Is there any doc available?

Does it lags more with this patch then without? (With Blockmen's version it does.)


I did document the function in my branch, although it's probably useless now. And yes... my code still leaves the local player be networked like all other players, so you still see yourself in server-side movement.

To fix this, we need to override the position and rotation of the local player's entity client side, to use the information we know locally about our position rather than having the server send it like for other players. When this is done, we should also stop the server from sending a player their own position / rotation, to no longer waste bandwidth unnecessarily.

PostPosted: Sat Apr 12, 2014 21:04
by MirceaKitsune
BlockMen's third-person view code was added to Minetest GIT today. Go check it out! It has the eye offset feature, and sometime we can hopefully look into an ability to attach the camera on entities too.