Jump to content

Drawing Firing Arcs


Recommended Posts

I am building the GUI for my Bridge Sim. The end result will be something like the images below. The game is in 3D, but the weapons view is a locked camera on top.

Visually I would like it to look like the top image here, with a pulsing gradient texture. Functionally I would need to be able to set a 'forward' angle and then the beginning and ends of the arc (up to a full circle), then the arc would move with the gun/ship as it rotated.

I am guessing that it is best achieved in 3D, rather than 2D so I can use animated materials and textures. What is the best direction to go and how should I get started?


Link to comment
Share on other sites

16 minutes ago, Kreeba said:

Because it uses the shortest angle between two axis to draw the arc.

The given example is calculating the angle from two given vectors and is designed to use the smallest angle. In your case it seems that you already know the angle and so it does not have to be calculated. Hence the example can be adapted, as a starting point, to meet your needs , you just pass the start vector and the angle rather than two vectors.:)

Link to comment
Share on other sites

I guess, if I ignore the arc and just treat it as a AABB style detection. See if the object is within the two angles of the detector object. Then check for min and max distances.

I hate maths:



Too be honest I could use a little help converting this into something that will work with Babylon/pure JS. Also would need a Min/Mac distance check (he talks about this at the bottom)

Link to comment
Share on other sites

Thanks. I need to do this without Babylon as it also has to run on the server for verification. The second link I posted looks the easiest. However my maths is nowhere good enough to think how it will work if the gun is parented to a moving ship, and the gun is fixed (so the firing arc will move).



Link to comment
Share on other sites

OK this has absolutely stumped me.

I am trying to get it to work with y axis rotation (for when the ships are turning)........I applied a offsetAngle variable to the code, but it totally messes up when the radians flip from + to - 

Can anyone help with the best way to handle y axis rotation?


Link to comment
Share on other sites

This seemed interesting, so I had a play about with it.


I'm not entirely sure if that's sort of what you were getting at or not, so let me know.



Mistake in first pg when sphere not at origin, see lines 110 to 112 --> I'd translated an already translated point

Link to comment
Share on other sites

Sable, could this be adapted so it didn't use the babylon line let distance = BABYLON.Vector3.Distance(point, center);?

Eventually I would like to also run this function server-side for verification, and wouldn't have access to the Babylon framework? This is why I did my own distance calculation using sqrt before.


Link to comment
Share on other sites

All that is doing is subtracting the center vector from the point vector and storing it in another vector called _translatedPoint.

Vector3.prototype.subtractToRef = function (otherVector, result) {
    result.x = this.x - otherVector.x;
    result.y = this.y - otherVector.y;
    result.z = this.z - otherVector.z;
    return this;


Link to comment
Share on other sites

  • 2 weeks later...

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