How to make the Camera have collision detection Physi.js First Person Shooter - camera

Project Premise
The idea for my THREE.js game is the have the player navigate though a maze of objects and reach an exit. I need collision detection not just for cubes and spheres, but also models imported from Blender. I thought about using RayCasting but I decided to go with Physi.js.
The Problem
,The idea is to give the camera a "body" so that the player can't pass though wall or other objects like they can when they are just a camera object. However, My "player" object seems to loses all of its Physi.js attributes as soon as I give it THREE.PointerLockControls(player). What I'm doing is creating a Physijs.BoxMesh, the player, and adding the camera to that. After that I pass the "player" object to my setupControls() function.
var geometry = new THREE.BoxGeometry( 500, 500, 500 );
var material = new THREE.MeshPhongMaterial( {color: 0x0000FF} );
player = new Physijs.BoxMesh(geometry, material, 1, {restitution: .9, friction: .1});
scene.add(camera);
scene.add(player);
player.add(camera);
//give player control of THIS mesh.
setupControls(player);
The Controls work as expected, I can control the player mesh with the camera stuck to it creating an FPS view, but I when I do this I can still move though walls and other objects. I've even moved the camera back on the Z position to confirm whats going on and I can see that the player mesh is just passing though objects instead of being hindered or knocking them over.
Solutions?
If I remove setupControls(player), then the Physi.js physics begin to work on the player mesh! It will fall from gravity, bounces around and everything. It looks really cool, but now I can't control it! It seems like I can only have one or the other lol. So does anyone know what I could do to solve this problem? Is what I'm preposing even possible? I'm new to THREE.js so any input is much appreciated!

Related

How to Create a 3D Shaky Camera Effect in GML

I am currently working on a project in GameMaker:S.
I want to know how I would create an effect where the 3D camera bobs around, as if it is being held by somebody with unsteady hands? I've been trying to figure something out for a couple of days now.
Cheers.
1.Maybe you can create an invisible object, edit it so it can randomly teleport or move to locations and then make the view[0] to follow it.
or you can create a path for the object to follow.
2.You can create a variable like; x = irandom(-100,100) and set the view to follow it.
3.Use the most foolish method: instead of camera, let everything else move so that the player things camera is moving. You can do this by randomly moving background, objects etc.

Unity2d; How to raise(lift) camera during game mode at a fixed y axis minimum

I may be making this harder than what it really is, but I am also pretty new to developing games. Currently I am making a practice scene to get back used to the unity engine as I have not had time to use it since last summer. My issue is that I can not figure out how to lift the camera in game mode. Notice my photo below, and how much of the "underground" is showing. I want to raise the camera to keep it at the very least a specific y axis value, so that I can make less of the ground visible, and more of the background visible. If I am over complicating this, please also let me know. Thank you
If main camera is still then just lift the camera in scene view you can see changes in game view.
Or if camera moves with respect to player then you have to use a script and attach it to camera and get a reference of player transform in the script and according to the player position change position of the camera. Add an offset value in y component of the camera.

Blender to Unity: Object shifting positions

I have a model that I created in Blender. I then created a bow and arrow and then parented it to the hand bone of the model so that it moves with the hand. When I use the .blend file in Unity, however,the bow and arrow shifts to some other position away from where it is supposed to be. I'm not entirely sure how Unity and Blender's co-ordinate systems differ so it might be that but I haven't really had this problem with other models before. Any help would be appreciated.
Edit: Ok, so I've figured out what the problem is but I have no idea how to fix it (apologies for my poor modelling practices in advance because i'm fairly new to this)
This is my model in pose position:
This is my model in rest position:
I connected the bow to the skeleton by clicking on the bow rig > shift clicking on the hand bone > CNTRL+P > to bone. This works fine as the bow now moves with the skeleton and I can do whatever I need in the NLA editor.
Now, the issue is, when I use the .blend file in Unity, the bow is in the rest position of my model even though the skeleton is in pose position and performing the actions (so the bow is floating on the side).
I've tried connecting it differently. If I connect the bow instead of the bow rig to the model, then it is in the correct position in unity but then the bow rig detaches and so the bow animations don't play.
I've also thought the problem would be solved if I make the the current pose position my rest position but when I do that, the mesh reverts to the old rest position and moves very weirdly with the skeleton. Here is that pic:
I would really, really appreciated any help with this as it's been hindering my progress for the past few days.
This method describes saving the hierarchical assignment of a handheld object until after the character and animations are exported to unity. The weapon is imported separately in Unity and then assigned as a child to the relevant bone at that time.
Assigning a handheld object to a blender generated character.

Changing game size in Phaser dynamically

I'm building a game in which I can enter a building, which I'm handling via states. In other words, when my character overlaps with the door, the program starts a new state in which the interior of the building is built. Now, I want the interior to have smaller dimensions than the world, so I want to change the game size when I start this new state.
I tried this:
create: function()
{
//game size was 1000x700, I want to scale it to 700x450
game.width = 700;
game.height = 450;
//rest of creation code...
}
I also tried things like changing camera bounds, world bounds, world size, but method above shows the most promise.
The problem, however, is that the resize for some reason does not show until I click away from my browser tab and back. Calling game.width in the console yields 700 at all times, but it doesn't show it as such until tabbing out and back.
On top of that, the contents of the game (floor, furniture) are scaled down when the game resizes, defeating the purpose. I don't understand why it would, since there's no scaling anywhere in my code.
Any help would be greatly appreciated.
Edit:
I just saw that you were the one asking the question I linked to, so I guess the question is solved :D
I had a similar problem some time ago. As you described yourself: what you are doing is a resize! So the game resizes itself which means the same as re-scaling everything in the game.
if you want to cut the game smaller you can simply use
game.scale.setGameSize(700, 450);.
(see this post if you need more information)
As additional information: I later had problems with cutting the game size equally on all sides, so if you should come to face the same problem, have a look at this post

Three.js 3rd person camera

I'm trying to create a 3rd person camera view in three.js
I'm using the THREE.FirstPersonControls(); on my camera. Then setting the rotation and positions of my "player" objects to be the same as the camera with some offsets.
This does not seem to work.
What i'm more wondering is if I should be adding my FirstPersonControls to the camera and then rendering the "player" infront of it. Or adding the controls to the player then making the camera always point at the back of the player?
EDIT:
I've tried setting the player object to be a sub object of the camera using camera.add(player);
but moving the camera around is not moving the player. I thought adding an child element would mean they move together?
EDIT 2:
I took another approach of adding both the camera and the player to a group then adding my 1st person controls to that group... Now both the camera and the player do get rendered. But it's completely thrown off how the first person controls worked. (e.g. looking down goes left etc etc)
Thanks for any help,
James
First of all, the Controls were designed to be controlling a camera, and not an object. And since by default, objects look "up" the z-axis, and cameras look "down" the z-axis, it is unlikely that the Controls will work as expected when applied to something other than a camera.
Secondly, the Controls are part of the examples, and not the library, so they are not officially supported. You are free to hack away at them.
One way to achieve what you want is to make the camera a child of your player. Something like this:
player.add( camera );
camera.position.set( 0, 50, 100 );
You may, in your render loop, need to set:
camera.lookAt( player.position );
Then you want to control the player with the mouse or keyboard. Your best bet is to write your own controller to do that. There are plenty of examples on the net.