Jump to content

Camera smooth reset position;


hulahula
 Share

Recommended Posts

Hello evryone :)

Sorry in advance for my bad english;

I wanna ask somthing about .ArcRotateCamera ();

I want to make camera with locked position behind the player when the player moving but if player stand on the place he can moving around with  the camera and when he again start moving the camera smoothly  rotating to the  locked position. I wondered  if I will make somehow the camera will checking position.z of the player then camera will be calculate  position  behind the player.  Here is my player how move in game 

for better understending: http://www.babylonjs-playground.com/#TGA1QA

By the way I only want some tips or show me a way how I can make this work out :) I want to fully understand how javascript and babylon.js works. Thank you.

Link to comment
Share on other sites

Hi Alenvei! 

Here is a playground that I have been working-on.

https://www.babylonjs-playground.com/#TGA1QA#1

This uses a followCamera when player box is moving (WAD keys), and switches to a free camera that is hovering over the player's head... when player box not moving.  The free cam is fully pan/tilt powered.  Player first-person view.  (I hope that is the objective.  If not, Alenvei will correct me.)  :)

I'm just starting... and I could use help from others.  I turned-on showBoundingBox on player box... and when in freecam mode, you can tilt camera down and see the box below us.

Line 16... the followCam constructor... needed a mesh as a lockedTarget parameter, so the box needed to be created BEFORE the followCamera.

I'm doing some forced-adjusting of scene.activeCameras... but maybe not needed.  Still learning.  :)

Generally, most of the 'work' is happening in lines 49-51, and lines 60-67.  Just playing in the playground... seeing what happens.  Fun!

Problem#1:  When WAD-key moving stops, free camera needs Y rotation adjustment... so it is aiming same direction as player is facing.  Easy fix for many... but Wingnut struggles with direction vectors... often.  Help welcome.

Problem #2:  When HOLDING 'W' key, while using A and D keys for steering (multiple keys held at same time)... the followCam does something strange.  Around line 60... we need...  if no other keys are pressed {...  In other words, don't switch to freeCAM... if TWO keys were being held, and only ONE of them... was released.  Still thinking about how.  Help welcome.

Ok, that's all I have for now.  I have some errands to run... but maybe others will advance this and fix some of its problems... real soon.

This method doesn't use an arcRotate cam... but it is still pretty nice... because of the followCamera.

A cool "extra feature" might be... having the followCam animate/ease-into freeCam view... after player movement is stopped.  That would be sweet!  More soon, stay tuned.

All ideas welcome.  Party on!

More stuff:  In my opinion, Alenvei's idea is VERY good. SO MUCH good, that we need a camera with 'behaviors' that are precisely as described.  A free camera... on the player... that becomes a chase/follow cam... if the player starts moving away-from current camera.position.  The faster the player moves... the more follow radius (distance) (optional :) ) Anyway, it seems that a camera that did this behavior by default... would rock!  Very useful... it seems.  And I think it would be cool... to make the switch-to-follow point... speed-adjustable.  Player must move SOME speed/distance before we switch to following-view.  That way... a player can slightly adjust position for the freecam... like sneaking a look around a corner... nicely... without the cam changing to follow mode with every little move.  Right now, the #1 playground sort-of SUCKS.... because of switching to followCam with every single move keypress.  It should maybe wait for keypress auto-repeating to start... and THEN switch to followCam/chaseCam.  hmm.  Cool cam system... if we can get it done.  A freecam... that eases in/out of followcam mode.  Sweet.  First person, third person, first person, third person, am I a player or am I only watching?  heh.  Maybe only go to followCam... when player is running, not walking.  hmm.  Cool.

Link to comment
Share on other sites

Hello @Wingnut

Your exampel it's very cool  I realy like it ...thank you :).But this is not what i am looking for. The game what I am working is RPG game. And my I idea is make camera,  which player can see  of  terrain  around him  and if he don't want the "free view funcion " player press for exampel "C" key for  funcion camera locked behind player and here is thing,  he can still moving around the camera but when he press the "WASD" keys then camera smoothly rotate behind the player. If I use camera.parent = player; instead camera.target = player; then value of the camera.alpha  is not changed, this is great  because we know starting point  of our  camera, which in my case is value = 4.71238898038469; but when plyer start rotate whith camera becous he want to see terrain of course :D  value of the  camera.alpha starts to increase, so here is question:

How can I make the  camera calculate  rotatation exatly behind the player ?

During  writing this coment I set the rotation of the camera like this :

  if (camera.beta < 0.1){

      camera.beta = 0.1

   }else if(camera.beta > (Math.PI / 2 *0.95) ){

              camera.beta = (Math.PI / 2 *0.95)
          }
               
  if(camera.alpha < 4.71238898038469 - Math.PI){

     camera.alpha = 4.71238898038469 - Math.PI

   }else if (camera.alpha > 4.71238898038469 + Math.PI){

             camera.alpha = 4.71238898038469 + Math.PI;

          }

So if player rotate:  - Math.PI or +Math.PI; with this I make for the camera some borders  so we can now easily calculate how far the camera rotate.

Ok now if the camera rotate for exmapel to the camera.alpha = 2.71;  then we need value  2  because 2.71+2 = 4.71:(this is value of camera.alpha behind the player ) simpel math right ? :)

Here is code what I mean  almost with my silly math exampel :D

if(camera.alpha!=4.71238898038469){
   camera.alpha +=0.01;
 }

but  it never will by exactly 4.71238898038469;

I know you are asking .... "where is your math exampel what you write higher in the coment ?" ... the truth is I don't know how  implement this exampel I only know that I can make it with for() loop; but I don't  have so much experience.

What you thing it is posible make something like that ? 

Again sorry for my bad english :D

If anything is unclear,  let me know .

Link to comment
Share on other sites

ehm  i think i figured out :D when i posted my last comment I tried this :

  if (camera.alpha < 4.71238898038469){
             camera.alpha += 0.04;
            }
  if(camera.alpha > 4.71238898038469){
              camera.alpha -= 0.04;
            }

and it worked :D i think this forum has some wierd aura or somthing :D always when I post some issue a few minutes leter  I figured out out what I need :D

Thanks again for you long post @Wingnut   :) 

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