Jump to content

Third Person Dogfight Camera


Recommended Posts

(DISCLAIMER: I am new with Babylon.js so sorry if I'm asking stupid questions or act stupid when replying to you)

So I am trying to create a third person dogfight game but the problem with the follow camera is that it doesn't follow the player ok the Y axis as it does when moving in the Z axis(When I rotate the object on the X axis and move the forward it doesn't act the same as when I rotate on the Y axis and move forward at the same time). Is there another camera I should use or should I try and modify the follow camera or something. Thanks!

Link to comment
Share on other sites

Hi BTW, and hi DK, too.

I think Brick is going to need a "flight path" to do camera tests/modifications-with, and we have no flight path generator.

I would say @jerome's rollercoaster is one of our better "static" flight paths.  It uses a followCamera in line 178 with some kind of real-time radius adjuster in line 230.

But, it seems that the camera never tilts on X-axis, as BTW mentions.

Let's pretend... a "chase airplane" is following the purple "wagon".  Let's pretend that a human in the passenger seat of the chase plane... is holding/aiming the camera.

If the wagon makes an extreme climb or dive, there would likely be a two-step process.  The camera operator would tilt the camera to try to follow the wagon, and that would likely happen fairly fast.  Meantime, the pilot of the chase plane... would begin climbing/diving... chasing the wagon.

When/if the chase plane got (back) onto the path of the wagon, the camera operator would then de-tilt the camera and start aiming the camera more straight-ahead.

If we watch the rollercoaster demo carefully, we can see that the camera is always (trying-to?) matching altitude with the wagon (camera never x-tilts, or not very much).

Just for fun, I did some adjustments... disabling line 230, and adding a camera tilt report-to-console in line 233 [link pg #28].  As we can see by watching console, camera IS tilting SOME.  The camera never needs to tilt very much, because the camera's altitude is continuously changing - to match wagon.

Let's try another [link pg #29].  This time, I locked the followCam altitude at 50 units (in line 233).  NOW, the X-tilt values seen on-console... are much more extreme.  The tilting is "dictated" by the location of the .lockedTarget set in line 179.

Just some interesting things to learn-from and think-about.  (okay, okay, perhaps not very interesting, but I still wanted to talk about some stuff and do some basic tests.)  :D  Party on.

PS:  BTW... it IS quite possible to FLY the wagon yourself (no rollercoaster tracks), using one camera aiming out the front of the lead airplane (so you could fly it properly), and have a "panel" on your dashboard that shows a "renderTargetTexture" (RTT) of the followCam from the chase plane (a view from the chase-plane followCam).  Although that scene would require some serious work, that would be the ultimate test-bed for your followCam.  Ever heard the phrase "fake them out of their jock strap"?  :)  Well, if your lead plane could make extreme turns, dives and climbs, you could do some of those (as pilot of the lead airplane), and "watch" (on the RTT panel) when/how-often your flying skills were able to "fake out" or "deek" the chase plane and its camera operator.  :)

Link to comment
Share on other sites

Hi thank you! I think you are starting to get at what I'm doing. This is a bit complexed for me and I was wondering if it was possible to do this by(again not very experienced) to have the camera like an arcrotatecamera change the alpha and beta to match that of the player and follow the player as well.

Link to comment
Share on other sites

:)  Don't let him scare you, Brick.  P8 has been snorting bytes since noon today... he's already well code-toasted.  :D

Inertia, reaction times, camera mass, overshoot, heavy momentum goods.  (Wingnut opens the top of Pryme's head and looks around in there.)

He calls it "the basics".  heh.  Um, the basics would be a nice playground with BabylonGUI sliders to adjust all the variables WHILE a violent high-speed chase is underway.  :)

Anyway, here's a terrible flight sim with a ton of BROKEN cameras and buttons, but it was ONCE used to test airplane-following cameras.  With a little (a lot of) work, it could be hammered into being a follow-cam testing scene, once again.  Perhaps @Pryme8 will install one of his inertia-cams in a new blue button.  :)  Perhaps someone will fix all the other broken cameras.  Perhaps we need a robot stunt pilot for this airplane.  

Maybe much later, we spawn 5 of these airplanes and do a 1930's "Blue Angels" show!  Cooooool.  Five robot stunt pilots... communicating with each other... doing an air show for us.  "Keep it inside the skybox and above the ground, boys"  :)  Air show choreography comes from a "script" or maybe a block of xml nodes.  Excellent!

I'll code the smoke systems for the planes.  Sound good?  Let's GO!  :)

Link to comment
Share on other sites

Hi and a warm welcome from me. The following PG uses the ArcFollowCamera which allows you to change the alpha and beta values. Hope it sets you on the way to what you want.


By the way as Deltakosh mentions, it is always a good idea to set up a simple PG showing your issue with other aspects of your project stripped out. It makes it much easier to see what you need.

Good luck with your project.

Link to comment
Share on other sites

59 minutes ago, Bricktheworld said:

Thank you!

Just one question, do you know if there was a way to animate the camera to have the same alpha and beta as the player?

Probably but I do not know what your player is doing or how the player's alpha and beta are changing. Presumably the player has a controlling device and you are taking the readings from that device, and these give you alpha and beta values for your player which can then be used for the camera.

Link to comment
Share on other sites

See if this helps.


A third person camera

keys "a" and "d" rotates the character left and right , in other words rotates the character around y axis  and the camera seems to follow.  
I say seem because that is not quite true.
It is not the camera which follows the character but the character which follows the camera :)  
Rotate the camera and then rotate the character based on the camera rotation

Here's the code

Here are the lines for rotation


Link to comment
Share on other sites

2 hours ago, Bricktheworld said:

Just one question, do you know if there was a way to animate the camera to have the same alpha and beta as the player?

Hi guys.  Brick... folks often "bind" or "wire-together" things inside the scene's renderLoop. 

One of the most common...

          camera.beta = player.rotation.x;  // this line can get lots more complicated
          // lots more stuff that gets done every frame

Some cameras don't have beta, so then camera.rotation.x = player.rotation.x, or maybe venture into camera.rotationQuaternion and visit BJS Quaternion yaw/pitch/roll methods. (Quaternions aren't always an easy-learn, though).

Sometimes you might use += or -= in place of =

Sometimes, you need things like camera.rotation.addInPlace(player.rotation);  Fun, demented wire-ups/bindings.

Anyway, I just wanted to show you how to "bind" things to other things, with the render loop.  Sort of like patch cords, eh?

A reminder to forum helpers... Brickster is most-concerned with making a standard followArcCamera... be able to follow nicely when player does STEEP Y position changes... needing camera POSITION to "follow" nicely.  (I hope I re-stated correctly, Mr.Brick) :)

Our followCams do okay when following left/right turns, but do they follow JUST AS NICELY when player does steep drops and rises?  I think this is Brick's initial concern.  The ArcFollow might TILT .beta nicely, but does it have good position-following when target does large Y-pos changes?  I bet, when player drops quickly into a deep valley, our followCameras will smuck-into the ground... in an attempt to follow (dependent upon camera followDistance).

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.

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.


  • Recently Browsing   0 members

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