First-person Camera and controls/collisions, how?


photo

Recommended Posts

In the docs, the camera referred to as third-person. How do we spawn/initialize FPS cam in Unigine and control it? How do we set collisions for it and a make it sway as in typical FPS game? Thank you.

 

EDIT: http://i.imgur.com/MCnbA.jpg << I need to achieve #3. This way I have shadows cast by the player's model, I see player in the reflection, for I only see vweap model (arms and guns) in the view. That's how pretty much most FPS games work.

Edited by alexander.zubov
Link to post

great picture --

Have a look at the character demo....

It has three components

A playerActor that is controlled by the controls

A mesh animation tree that follows the playerActor

A playerPersecutor that follows a particular bone in the mesh.

 

To do what you are asking one can simply hack the character script scripts/character or

you can just set up something using A playerActor and a mesh....

 

It would however be a fairly good idea for Unigine to provide a first person character rig like the one you are suggesting and/or make that easier to set up with the character scripts.

Link to post

Right. To my understanding, our coder figured it out. The issue is with drawing vweap model.

 

I am using Quake 4 vweap model for prototyping. There are few issues. First issue is that the model gets clipped, as if there is a near clipping plane on the camera. So when we adjust model's origin for it to appear in view properly, it gets chopped. Second issue is that it doesn't look right. As if ID Tech 4 users different ways of drawing vweap models compare to the rest of the game's world.

 

Anyone from Unigine team can help out please?

Link to post

How do we spawn/initialize FPS cam in Unigine and control it? How do we set collisions for it and a make it sway as in typical FPS game?

Danni Coy described it absolutely right:

* You can try out Character system or

* manually create your first person character rig using ObjectMeshSkinned to show model and play animation, PlayerActor to handle controls and interact physically (it is approximated with a capsule) and PlayerPersecutor for camera to follow the specific bone.

 

I need to achieve #3. This way I have shadows cast by the player's model, I see player in the reflection, for I only see vweap model (arms and guns) in the view.

Unigine is very flexible when it comes to adjusting what you see in the viewport. For example, to draw a shadow without drawing the mesh itself you can:

  1. go to the Materials editor -> States tab
  2. Set Deferred and Ambient passes to Skip.

Check also a Viewport mask used to skip rendering of objects in the viewport (together with shadows).

 

First issue is that the model gets clipped, as if there is a near clipping plane on the camera. So when we adjust model's origin for it to appear in view properly, it gets chopped.

You can control the near clipping plane via Tools->Camera->Near clipping parameter (in the editor) and Player::setZNear for your player persecutor. Beware though, small values decrease the depth precision.

Link to post

Beware though, small values decrease the depth precision.

Just a thought, but it might be possible to overcome weapon near-clipping plane issues by rendering the FPS weapon model to a WidgetSpriteNode overlayed over the actual scene as described here. For the WidgetSpriteNode projection matrix a much smaller depth range could be specified than for the rest of the scene.

Link to post

BTW, you can also check Sanctuary demo: Camera button -> Candle mode. This mode was actually intended for FPS reference.

Link to post
  • 3 weeks later...

I want to achieve a FPS camera too and I want to know what is the best way to do it with Unigine.

Sanctuary demo uses an FPS camera but it's more like an spectator than a real FPS camera (no gravity and no character presence)

 

Using actor_00 demo, and teaking it as follows:

actor = new PlayerActor();
actor.setPosition(Vec3(-10.0f,0.0f,2.0f));
actor.setMinThetaAngle(-80.0f);
actor.setMaxThetaAngle(80.0f);
actor.setThetaAngle(20.0f);
actor.setJumping(1.0f);

actor_skinned = new PlayerActorSkinned(actor);

persecutor = new PlayerPersecutor();
persecutor.setPosition(Vec3(-20.0f,0.0f,2.0f));
persecutor.setControls(0);
persecutor.setTarget(actor);
persecutor.setAnchor(vec3(0.0f,0.0f,1.65f));
persecutor.setMinDistance(0.15f);
persecutor.setMaxDistance(0.15f);
persecutor.setMinThetaAngle(-80.0f);
persecutor.setMaxThetaAngle(80.0f);
persecutor.setFixed(0);
persecutor.setSpatial(0);
persecutor.setCollision(0);
engine.game.setPlayer(persecutor);

with a weapon model attached to persecutor it looks convincing.

 

Now I want to simulate camera bobbing and swaying as player moves across the level.

What could be the best way to achieve it in Unigine? It's something related with locators? How can I use them?

 

Thanks for your help,

Iván.

  • Like 1
Link to post

Hmm.. I thought DarkPlaces engine support was horrible...

 

EDIT: So no one is skilled enough with Unigine to help out 2-men team?

  • Like 1
Link to post

This is my current

implementation.

 

Now I need to implement camera roll when player moves left to right and viceversa. With persecutor I can only modify Phi (yaw) and Theta (pitch) angles.

I've tried with persecutor.setRotation() but it does nothing.

 

Any idea?

Link to post

Players cannot be rotated via Node::setRotation() as they are handled differently from all other nodes. I'll add it to docs. Use PlayerPersecutor::setViewDirection() instead.

 

It it would be of any help, you can use attached files as a draft for FPS actor. It seems to be pretty much what you want to achieve, Ivan.

 

Thanks :)

Link to post

Manguste,

Unfortunately there are some problems with your sample:

21:49:34 Loading "D:/_development_/_external_/UNIGINE/UnigineSDK-source-2012-02-26/bin/unigine.cfg"...
21:49:34 Data path: D:/_development_/_external_/UNIGINE/UnigineSDK-source-2012-02-26/data/
21:49:34 Loading "d3d9.dll"...
21:49:34 Set 1024x768 windowed video mode
21:49:34 Set 1.00 gamma value
21:49:34 Unigine engine http://unigine.com/
21:49:34 Binary: Windows 32bit Visual C++ 1600 Release Feb 26 2012 r8521
21:49:34 Features: OpenGL Direct3D9 Direct3D10 Direct3D11 OpenAL XPad360 Joystick Flash Editor
21:49:34 Loading "openal32.dll"...
21:49:34 App path: D:/_development_/_external_/UNIGINE/UnigineSDK-source-2012-02-26/bin/
21:49:34 Save path: D:/_development_/_external_/UNIGINE/UnigineSDK-source-2012-02-26/bin/
21:49:34
21:49:34 ---- System ----
21:49:34 System: Windows 7 (build 7601, Service Pack 1) 32bit
21:49:34 CPU: Intel® Core™2 Quad CPU Q9550 @ 2.83GHz 2832MHz MMX SSE SSE2 SSE3 SSSE3 SSE41 HTT x4
21:49:34 GPU: NVIDIA GeForce GTX 260 8.17.12.8562 x1
21:49:34 System memory: 2047 Mb
21:49:34 Video memory: 896 Mb
21:49:34 Sync threads: 3
21:49:34 Async threads: 4
21:49:34
21:49:34 ---- MathLib ----
21:49:34 Set SSE2 simd processor
21:49:34
21:49:34 ---- Sound ----
21:49:34 Renderer: DirectSound Default
21:49:34 OpenAL vendor: OpenAL Community
21:49:34 OpenAL renderer: OpenAL Soft
21:49:34 OpenAL version: 1.1 ALSOFT 1.13
21:49:34 Found AL_EXT_LINEAR_DISTANCE
21:49:34 Found AL_EXT_OFFSET
21:49:34 Found ALC_EXT_EFX
21:49:34 Found EFX Filter
21:49:34 Found EFX Reverb
21:49:34 Found EAX Reverb
21:49:34 Found QUAD16 format
21:49:34 Found 51CHN16 format
21:49:34 Found 61CHN16 format
21:49:34 Found 71CHN16 format
21:49:34 Maximum sources: 256
21:49:34 Maximum effect slots: 4
21:49:34 Maximum auxiliary sends: 2
21:49:34
21:49:34 ---- Render ----
21:49:34 Renderer: NVIDIA NV50 896Mb
21:49:34 Direct3D9 desc: NVIDIA GeForce GTX 260
21:49:34 Direct3D9 driver: nvd3dum.dll
21:49:34 Found required D3DPTEXTURECAPS_CUBEMAP
21:49:34 Found required D3DPTEXTURECAPS_VOLUMEMAP
21:49:34 Found required D3DPTADDRESSCAPS_WRAP
21:49:34 Found required D3DPTADDRESSCAPS_CLAMP
21:49:34 Found required D3DCAPS2_CANAUTOGENMIPMAP
21:49:34 Found optional D3DPMISCCAPS_INDEPENDENTWRITEMASKS
21:49:34 Found optional Vertex shader 3.0
21:49:34 Found optional Pixel shader 3.0
21:49:34 Found optional Vertex texture fetch
21:49:34 Found optional HDR blending
21:49:34 Found optional HDR filtering
21:49:34 Found optional NULL texture
21:49:34 Found optional RGB10A2 texture
21:49:34 Found optional DXT texture compression
21:49:34 Found optional ATI texture compression 1
21:49:34 Found optional ATI texture compression 2
21:49:34 Found optional NVIDIA hardware shadow
21:49:34 Found optional NVIDIA alpha to coverage
21:49:34 Vertex instructions: 4096
21:49:34 Pixel instructions: 4096
21:49:34 Maximum texture size: 8192
21:49:34 Maximum texture units: 16
21:49:34 Maximum texture renders: 4
21:49:34
21:49:34 ---- Physics ----
21:49:34 Physics: Multi-threaded
21:49:34
21:49:34 ---- PathFind ----
21:49:34 PathFind: Multi-threaded
21:49:34
21:49:34 ---- Interpreter ----
21:49:34 Version: 2.47
21:49:34
21:49:34 Unigine~# editor_quit && world_load samples/players/actor_00
21:49:34 Loading "core/unigine.cpp" 8ms
21:49:34 Loading "core/locale/unigine.en" dictionary
21:49:34 Loading "core/materials/default/unigine_post.mat" 20 materials 44 shaders 2ms
21:49:34 Loading "core/materials/default/unigine_render.mat" 40 materials 4666 shaders 30ms
21:49:34 Loading "core/materials/default/unigine_mesh.mat" 5 materials 3386 shaders 24ms
21:49:34 Loading "core/materials/default/unigine_mesh_paint.mat" 2 materials 1134 shaders 7ms
21:49:34 Loading "core/materials/default/unigine_mesh_tessellation.mat" 5 materials 3332 shaders 20ms
21:49:34 Loading "core/materials/default/unigine_mesh_tessellation_paint.mat" 2 materials 2268 shaders 11ms
21:49:34 Loading "core/materials/default/unigine_mesh_triplanar.mat" 1 material 112 shaders 2ms
21:49:34 Loading "core/materials/default/unigine_mesh_terrain.mat" 1 material 53 shaders 3ms
21:49:34 Loading "core/materials/default/unigine_mesh_layer.mat" 1 material 84 shaders 3ms
21:49:34 Loading "core/materials/default/unigine_mesh_noise.mat" 1 material 106 shaders 5ms
21:49:34 Loading "core/materials/default/unigine_mesh_stem.mat" 2 materials 1268 shaders 12ms
21:49:34 Loading "core/materials/default/unigine_terrain.mat" 1 material 312 shaders 1ms
21:49:34 Loading "core/materials/default/unigine_grass.mat" 1 material 138 shaders 3ms
21:49:34 Loading "core/materials/default/unigine_particles.mat" 1 material 101 shaders 3ms
21:49:34 Loading "core/materials/default/unigine_billboard.mat" 1 material 51 shaders 3ms
21:49:34 Loading "core/materials/default/unigine_billboards.mat" 1 material 816 shaders 5ms
21:49:34 Loading "core/materials/default/unigine_volume.mat" 6 materials 45 shaders 8ms
21:49:34 Loading "core/materials/default/unigine_gui.mat" 1 material 82 shaders 1ms
21:49:34 Loading "core/materials/default/unigine_water.mat" 1 material 205 shaders 9ms
21:49:34 Loading "core/materials/default/unigine_sky.mat" 1 material 17 shaders 10ms
21:49:34 Loading "core/materials/default/unigine_decal.mat" 1 material 99 shaders 3ms
21:49:34 Loading "core/properties/unigine.prop" 2 properties 0ms
21:49:34 Editor::editor_quit(): editor is not loaded
21:49:34 NameSpace::check(): unused variable "space" in "create_scene" function
21:49:34 Loading "samples/players/actor_00.cpp" 36ms
21:49:34 Loading "samples/players/common/players.mat" 7 materials 7ms
21:49:34 Loading "samples/players/actor_00.world" 7ms
21:49:34 MeshSkinned::load_smesh(): wrong magic 0x3230736d in "samples/players/meshes/actor_00.smesh" file
21:49:34 MeshSkinned::load_sanim(): wrong magic 0x32307361 in "samples/players/meshes/actor_00/idle.sanim" file
21:49:34 MeshSkinned::load_sanim(): wrong magic 0x32307361 in "samples/players/meshes/actor_00/idle.sanim" file
21:49:35 MeshSkinned::load_sanim(): wrong magic 0x32307361 in "samples/players/meshes/actor_00/fire.sanim" file
<!-- Last line repeated multiple times-->

 

I've used actor file from SDK but it doesn't work as you can see post-59-0-14722900-1330377547_thumb.jpg.

Link to post

Sorry, I did not make myself totaly clear. It's NOT a working sample, it's just a reference, if needed. (It was a sample included in SDK a long time ago, so some things definitely changed.)

Link to post

@Ivan

Sorry, I misled you with players and rotation. All players can be rotated via setRotatation().

 

And good news, everyone. Our developers are going to create a FPS sample, most probably it'll be ready for the next SDK update.

  • Like 1
Link to post

Ooohhhh, that's sounds like a plan! Can't wait to see it. When is the next planned SDK release?

 

Will networking for FPS be there too? (with lag reduction and prediction)

 

Thanks!

Link to post

@Ivan

Sorry, I misled you with players and rotation. All players can be rotated via setRotatation().

 

And good news, everyone. Our developers are going to create a FPS sample, most probably it'll be ready for the next SDK update.

 

Any idea how long till the next SDK will be released?

Link to post

As long as they release it with working samples of FPS and networking for FPS :)

Link to post

No, networking for the FPS sample is not planned for now, just the basics (armor, health, pathfinding, Flash-based GUI, etc.).

Link to post