Jump to content

help as mesh move in the direction of the camera ?? ..


Recommended Posts

Hi @angeltrickz  You have not explained well, so it is difficult to help.

Maybe you want something like this?


Simple military tank-like mouse control.  Mouse forward, backward, left and right.  Mesh moves per pointer placement on canvas.  Keep in mind this is running on a half-screen canvas, so it would be wise to dynamically measure the size of the current canvas... and then use THOSE numbers in determining the values to use in lines 48, 52, 55 and 58 (for your project).

In other words, on a full screen canvas, those numbers will likely need to be different.  The perfect way... would be to use percentages.  In effect, if pointer is 30%-of-canvas-width LEFT... vehicle starts turning left, and conversely, if 30%-of canvas-width RIGHT, vehicle turns right.  Same for up/down (forward/backward)

It is easy to see your throttle and turn-speed values, here.

It's difficult to determine what you want... without a bit more information.  Please provide more, if you can.  thx!

Link to comment
Share on other sites

  • 3 months later...

Oh, sorry.  I have not followed-up on your issue... my apologies.  You want the enemy to be "attracted-to" (pursue) the player/camera.  *nod*

Have you had any success?  I have never tried this.  (I am more artist than game writer).

Perhaps, (in render loop) you would project a Babylon.ray from enemy to player... so you can get a direction-to-player.  Then, also in renderloop, move enemy along that direction vector... some amount.  Keep getting new direction with the ray... every frame... and the enemy might pursue the player.  Not sure.  I'll keep thinking.  Perhaps others will have ideas.

Again, sorry it took me so long to reply.

Link to comment
Share on other sites

Camera, Forward, controller, Magic Marble, Infinity... shit google Pryme8 3d Camera tutorial... like camera stuff is super easy to find information on and actually learning the math behind a lot of it will help you a lot.

Like if I ask you how do you get a cameras up vector from its forward vector, how would you do that?  Its super simple but if you don't know then I would advise doing research.

Everyone wants to be a game developer but no one wants to learn math, is starting to bug me... or maybe Im just in a bad mood today and Im taking it out on the forum... sorry.

Link to comment
Share on other sites


Like I understand asking questions, and I am guilty of asking topics that have been covered as well but usually not something so extensively covered.  I just am starting to feel like this website is less people asking questions and more just asking someone to do it for them.  This Thread is not guilty of that but I was triggered for some reason, I apologize, if I get a second to break away from work this morning ill post information on it.  But I do encourage you to google manipulation of 3d cameras.

Link to comment
Share on other sites

Nod.  The subject is not really about cameras.  The subject is moving enemy mesh toward camera/player.  I believe this might be related to "path-finding".  Is path-finding simple?  I never thought so, and I never thought it was EVER "extensively covered".  But I'm wrong, often.

20 minutes ago, Pryme8 said:

Everyone wants to be a game developer but no one wants to learn math

I find that... SOME people want to be forum helpers, yet they don't want to enjoy the playground, and use its wonderful visualizing... for forum helping.  ;)

I can understand your frustration, P8.  Things come "natural" for you, cuz you're a friggin' genius.  But me, and some others... not so natural.  I failed Algebra One... 2.25 times in high school.  SOME people just don't do math well.  You don't have that problem... but many do.

Anyway, back to enemy mesh being attracted-to/moving-toward cams... with a smile and with kindness.  :)  Let's pretend the player is Elvis, and the enemy are teenage girls trying to get a touch or a kiss from him.  heh

Link to comment
Share on other sites

I failed algebra in high school too, I slept every day in it that and chemistry (screw chemistry at least the way they taught it).

Every bit of math I know is self taught, its all from reading and mock up after mock up after mock up...  like right now before I do any scripting in game for my retro flyer I am doing air density models with charts to figure out corrects density ratios for humidity temperature and altitude and a lift ratio to angle of attack and wing surface area.  I'm having trouble getting the output I want so instead of asking questions or making a bunk system its back to reading PHD papers and writing notes until there is enough competency on the topic to proceed.

Its the same for this, whats the core goal.  To Lerp or Smoothly Lerp a Camera between two points.  That's simple if you understand basic vector math and lerp functions so instead of jumping into a 3d environment how about going with two or even one, and figure out how to manually draw pixls on a canvas to a set rate between two points with a linear or smooth linear function.  Then get fancy and add a middle anchor point and some bezier or cubic curves... Learn the core process, and your goals will be so much easier.

But as a cheat you can look at this :


Link to comment
Share on other sites

But the subject is... moving many enemy mesh towards camera... constantly updated... (because camera is player and player is constantly changing position).  LERP's won't work, because they don't have time to complete... before player/camera has moved once again.  LERP target constantly going stale.

We need mesh seeking camera... constantly... slow pursuit (with optional path-finding around obstacles).  Can we at least get ON TOPIC?  That would be great. :)  Player is moving camera with player movement keys.  No need to move camera... but need to remember that camera is a constantly moving target.  Subject understood?  I hope so.

Link to comment
Share on other sites

I can handle this in my animation system, Queued Interpolation, coming soon.  Basically, I have expanded the POV sub-system to also have animation queues for most camera types & some lights, in addition to meshes. 

Meshes, cameras, & lights are all BABYLON.Node sub-classes.  The existing POV movement & rotation calculations in Mesh, however cannot be applied to Cameras & lights, so a very similar version that handles all is in the extension.

If you look at the link above, you will notice that there is both a movePOV and a calcMovePOV.  Basically, for some kind of follow, you can just use calcMovePOV to get an offset and add to the current position.  calcMovePOV does not actually move anything.

For keeping something in front of a moving camera, I do something like this:

scene.beforeCameraRender = function () {
    // move the pointlight to match where the camera is
    var camera = scene.activeCamera;
    light.position = camera.position;
     // position backstory label mesh to be in a constant spot in front of the camera
     // do it this way, as opposed to an orthagonal camera, so can be VR friendly
     var labelDistance = 25;
     var labelDownFromCenter =  -5;
     var labelPos = camera.position.add(cameraQueue.calcMovePOV(0, labelDownFromCenter, labelDistance));
     label.rotation = camera.rotation;
     label.position = labelPos;


Link to comment
Share on other sites

2 hours ago, Wingnut said:

But the subject is... moving many enemy mesh towards camera... constantly updated... (becasue camera is player and player is constantly changing position).  LERP's won't work, because they don't have time to complete... before player/camera has moved once again.  LERP target constantly going stale.

You can dynamically change the target of the lerp thats not problem.

And yes it if works lerping a camera to a target you can do the same for a enemy approaching the player.  If you need path finding for the points to lerp to you need to do research on https://en.wikipedia.org/wiki/A*_search_algorithm

and make sure you include some form of Bounded relaxation.

Path finding aside, the point you are targeting changing is moot, this is how you would do trajectory analysis in real time, to like say shoot a incoming missile down.


also having "Dumb AI" that tracks the player and just chases them is super simple you can get this done with no path finding.

Quick question, whats the final goal?  Like Enemies who go after the player, or like a chain of NPC's following a player etc?  If I know that I can give you the best method to try.

Link to comment
Share on other sites

Because I replied to it... very late.  Angel had a follow-up question that I didn't notice until yesterday.  Being the great custodian that I am (ahem), I HAD TO answer the follow-up question, whether I was seriously late or not.  Sorry for dredging-up 400 year old posts... but it was part of my "duty" to the forum.  In fact, it wasn't really a follow-up question.  It was a clarification, showing that I had wrongly-answered the initial question.  So, angel's question was completely un-answered, and it was all my fault.

Besides, "attracting" is an interesting topic, right?  And it is used in games quite often, yes?  Having your enemies close-in on you... puts good pressure on players, correct?  :)

P8, LERPS are pre-calculated things, right?  So if you change the lerp target halfway through completing a previous lerp path, you must re-calculate a new lerp path... from current enemy position, to new camera/player position.  This must be done EVERY TIME the player/camera moves, yes? 

And we haven't even started talking about rotating the enemy to face the new lerp target before beginning travel on its new path.  But I suppose setting enemy lookAt or billboardMode will always keep the enemy facing the player.  And that... might be the secret.

If the enemy is always looking-at the player... we can simply move the enemy along their localSpace z axis... and that will make them pursue the player... I think.  hmm.  @Pryme8... you should build us a testing playground with a player moving in large figure-8, and 10 enemies in hot pursuit.  I know you LOVE making playgrounds. :)  If the enemies cluster atop each other (which they WILL DO after a long pursuit)... then make them elbow each other and fight amongst themselves for position (re-spread them from each other... occasionally.)  Cooooool.  :) 

Or how about a "cluster fart"?  One of the pursuing enemies farts, and it stinks so bad... that everyone spreads out to get away from that nasty smell.  heh

Link to comment
Share on other sites

Haha sure I'll do it today, and yes with a set lerp it would stay the same but bassically you recalc the lerp on each step of it or at a set tick rate (to damper the AI response and not make them so accurate it hurts.)


umm I have to finish my phase of the scene I'm working on for my client today, then I'll give that a look.  You would be proud wingnut I picked up a real client from this website and the scene they are making me build is extensive.

I was hesitant at first because I was afraid it was too detailed and had way to many objects for webgl to handle it but suprise it can and so now I'm optimizing and getting a really cool asynchronous preset loader going that looks really cool.  I think they are gonna post it on here once I'm done and they said they would do nice post about working with a developer from our community.  

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