Jump to content

Better FPS camera hit detection and physics.


Pryme8
 Share

Recommended Posts

So I can totally do the normal ellipsoid camera movements and the same system as demonstrated by http://www.babylonjs.com/Demos/Espilit/
But Im really running into problems with making this handle like a real FPS controller, like with stepping over things, and how it handles slopes.

What would be a better solution? a Ray casting system, or strap a simple object inside of like Cannon and do a mesh hit detection on a hidden capsule...  Whats the best option?  I want something smooth and dynamic.

Link to comment
Share on other sites

Use the bullet physics javascript port.

https://github.com/armory3d/haxebullet

It's a haxe port, but you can find a javascript file ammo.js there. It's automatically ported from C++ to JS with Emscripten. It needs some time to get into it, but then you have first class physics. It's used btw in Blender.

You can create a single physics body out of your terrain vertices data. If you want to try it I can show you how to use it, I played around a little with it  and know how to make physic bodies out of indices and vertices. It's a little bit complicated first.

Link to comment
Share on other sites

http://pryme8.github.io/Magic_Marble/editor.html

I forgot I did a physics controller for this... porting it over now for FPS.

 

*UPDATE:
So I need help... for some reason im drawing a mental block on how to get my speeds play into effect on the forward vector
 

if(player_box.body.collisionResponse){
			player_box.body.grounded = true;
			}else{
			player_box.body.grounded = false;	
			}
							
							
			if(player_box.body.grounded){
			if(keys.w){
				if(player.speed.f < settings.speeds.normal.f){
					player.speed.f += settings.accel;
				}else{
				player.speed.f = settings.speeds.normal.f;
				}
								
			}else if(keys.s){
				if(player.speed.f > settings.speeds.normal.b){
					player.speed.f -= settings.accel;
				}else{
				player.speed.f = settings.speeds.normal.b;
				}	
			}
			
			if(keys.a){
				if(player.speed.s > settings.speeds.normal.s*-1){
					player.speed.s -= settings.accel;
				}else{
				player.speed.s = settings.speeds.normal.s*-1;
				}
			}
			
			if(keys.d ){
				if(player.speed.s < settings.speeds.normal.s){
					player.speed.s += settings.accel;
				}else{
				player.speed.s = settings.speeds.normal.s;
				}
			}
			
			
			 	player.speed.f*=0.8;
				player.speed.s*=0.8;
				player.speed.u=0;
				if(player.speed.f<0.05 && player.speed.f > -0.05){
					player.speed.f = 0;
				}
				if(player.speed.s<0.05 && player.speed.s > -0.05){
					player.speed.s = 0;
				}
				
				var forward = v3(player.speed.s,0,player.speed.f).subtract(scene.activeCamera.upVector).normalize();
				
				
			player_box.body.velocity.x = forward.x;
			player_box.body.velocity.z = forward.z;
			}

This example lets you move around forward backwards ect correctly but does not take the cameras current forward into account.

 

var forward = scene.activeCamera.getTarget().subtract(scene.activeCamera.position).normalize();

replacing forward with this, makes the direction of movement correct, but it is constant, and the speed restraints do not come into effect.

forward.x*= player.speed.s; forward.z*=player.speed.f;
but that makes things act really funky.

any ideas?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...