Jump to content

Camera follows a character ever cut by a wall?


Dad72
 Share

Recommended Posts

You are right, it is the world->local craziness :-)

http://playground.babylonjs.com/#1VITHH#15

You were totally right with your implementation except for the conversion back from the transform to the inverse world matrix of the cube. Now it somehow works.

notice how it corrects the scaling as well, this is why cam2 is not on the ray anymore. Would be interesting to find a solution for that as well.

Link to comment
Share on other sites

I think the same, it was just to demonstrate that it works.

I would set a fixed distance and constantly check for ray intersections with the nearest objects, depending on the direction of the camera. Then sen the camera's position according to those parameters.

To prevent the camera from leaving the ray's range I would simply avoid scaling walls. I assume walls are the main objects that should be checked for intersections. 

A small very quick demo, that is based on the implementation so far - http://playground.babylonjs.com/#1VITHH#16 . I have removed the scale to prevent the world coordinates conversion problem.

This should, of course, be improved.

 

BTW, my patch for the Ray class is already in GitHub, a help static function Ray.CreateNewFromTo(origin, endPoint) will create a ray from a point to a point defining a given distance. I think this will help these kind of problems.

Link to comment
Share on other sites

Did a tiny bit of work on it. Made a camera's collision array, which holds all the objects to be checked. Then I made it so if the camera intersects more than one object it picks the closest one.

http://playground.babylonjs.com/#1VITHH#17

Now we should to make it so we see a certain amount of the character. Idk how we would do this.

Link to comment
Share on other sites

A quick implementation of what you wanted - http://playground.babylonjs.com/#VQBG2 . try rotating the camera and "losing" the sphere. It is always in sight.

This is really just a "prototype". Fast check is on, so it will stop finding the next mesh if it found one. but still I do believe that if you have hundreds of walls you will have to somehow check it a bit better. there is plenty of room to improve this! 

 

//Edit - with keyboard shortcuts ('w' and 's') - http://playground.babylonjs.com/#VQBG2#1

Link to comment
Share on other sites

That's Fricken Awesome!!!!!

 

Now I think we should maybe send several rays, instead of one?

 

8J2aRtT.png

 

This would be to remove the partly blocking:

 

http://i.imgur.com/Q8z8tgv.png

 

The problem with a few rays you could still have this happen if the mesh is small enough to fit between the rays. 

Therefor, would it make sense to create a mesh to do it instead? Kinda like this:

 

http://i.imgur.com/XaZxaSs.png

 

We would have parameters such as "Camera Width" and "Camera Height", and "Target Width" and "Target Height"

 

Then the mesh would change shape every frame

 

Would that be possible?

Link to comment
Share on other sites

It is inevitable (and not because of causality!) - you will have to check all walls for the smallest distance. The pickWithRay function simply iterates through all meshes, according to the order you added them... Without changing the framework (to return an array of pickInfo and not just the last one it finds), the best way of doing it is this : 

http://playground.babylonjs.com/#VQBG2#5

I did two things -

  1. I am checking if a wall is in the scene's frustum and filtering it from the picking inspection  if it is not in the scene's frustum. This will prevent the pickInfo loop to run. I assume this inspection is faster than iterating through all of the meshes and not finding any pickInfo. (Note - this only works if we are using rays straight from the camera. otherwise the frustum needs to be calculated differently).
  2. I am running a pickInfo with fastCheck for EACH wall in frustum. This way I am getting the lowest distance from the object and setting it. The last implementation simply took the distance of the first object it found. 

This is the simplest way i see, without again changing the framework (this will be a breaking change, as suddenly an array is returned and not a single object. I am not sure this is what everyone wants :-) )

 

//EDIT - this has to be one of the most interesting forum thread i ever took part of :-) 

300 walls and still 60fps - http://playground.babylonjs.com/#VQBG2#6 , looks like it is good enough to be used live.

Link to comment
Share on other sites

raananw can send your first fixed :

if(max == -Infinity) {     max = Infinity; }

I had some problem to request a pull, I do not know how I think. this is the first time I used a GitHub repository. I use bitbucket most of the time and it does not work in the same ways.

 

DK So, it would be interesting to have a little tutorial to send patches to the deposit by that I admit there feel really stupid. :(  :wacko:  :ph34r:

 

 

 
 
Link to comment
Share on other sites

  • 2 months later...

Hi dad72,

The reason it happens is that the camera's radius is set every frame. The variable "radius" is the max distance between the camera and the object. And it's set at the render loop.

I guess the loop could be implemented differently to allow zooming in or out until it his a wall.

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...