- Home /
Object Bounds From a Specific View Point/Direction
SCENARIO: I am trying to simulate wind "shadow" effects on a sailboat (known as "blanketing"). I have a "sail" object on each boat. If the sail on boat A is in the wind "shadow" of boat B then boat A will move slower.
My plan was to have a box collider that extends from the boat and away from the boat in the direction that the wind is blowing (just a vector). If another boat's "sails" are within that collider they are in wind shadow and have reduced speed.
My problem is that the width of the collider will be different depending on the angle of the wind relative to the sail. I need to figure out how wide to make the collider.
QUESTION: So, how can I determine the bounds of the sail as "seen" from the wind direction? This only needs to be determined in the X/Z plane (parallel to the water surface).
Thanks.
Not really the answer to your question but possibly an alternative solution:
You could use rays that start from the corner vertices of the sail, using the same direction as the wind vector and use them to check if any (or multiple) collide with the sail of the other ship.
Answer by imgodot · Feb 24, 2017 at 04:28 PM
whisp, Thanks for the reply.
I thought of using raycasts, and that may be where I end up, but there are some nuances. I don't want the shadow to be all or nothing, I want partial shadowing as well where only part of the sail is in the wind shadow of another boat. Also, the boat may be heeling (leaning/rotated away from the wind) so it might be hard to hit the sail itself with raycasts.
Expanding on my initial idea: I would have several gameobjects (Shadow_GOs) along the bottom edge of the sail that would move with the sail as it rotates. I had hoped to test how many of the Shadow_GOs are in the wind "shadow" collider of any other boat and reduce the speed accordingly.
Another idea: Add a very thin box collider to the sail (sail_collider), standing vertically. Raycast from the Shadow_GOs of other boats in the direction the wind is coming from. If they hit the sail_collider of another boat then those Shadow_GOs are in the wind shadow. The total # of Shadow_GOs in the wind shadow of other boats reduces the speed appropriately.
Sorry, if this is confusing, I'm rushed writing this.
You could certainly use the corner vertices to calculate the extends of such a collision box as you mentioned it in your main question, but you had to change the box every frame, respectively whenever the ships rotation and/or wind direction changes.
$$anonymous$$aybe you could start with a sphere cast with extends that guarantee to cover the whole sail. And when this sphere cast reports a collision with another ship's sail, do the more detailled calculations.
$$anonymous$$aybe there are even ways to calculate this in a shader, e.g. by using a directional light (using the wind direction) and when sail 1 casts a shadow on sail 2, use the light information to calculate the amount of wind impacting sail 2: unshaded parts = wind, shaded parts = no wind.
Probably there are better ways to do this, but i'm not the one who knows them.
Answer by mmciver · Feb 24, 2017 at 11:41 PM
I think this talk gives the core of what you are looking for: https://www.youtube.com/watch?v=OOeA0pJ8Y2s
I agree with the raycast option. You can get the sail corners easily enough. Raycast from them in the direction of the wind. If you have 4 corners and 3 of the 4 raycasts hit a sale, simple enough to call that 3/4ths (75%) blocked. However, if you wanted higher resolution, then it's a simple matter to get a distribution of edge points with some Lerping, and either math or more lerping to get points on the sail surface. Cast from those as well for a more precise calculation of effect. How high a resolution is entirely up to you, Lerp 0.5 for 5 more points, 11% steps of resolution, 0.33 for 12 more points, 6.25% steps of resolution. I doubt I'd go further, but you could for sure.
This also has some side advantages, such as also giving you the distance to the object creating the wind shadow, which should be important to the math (I love sailing physics). A bigger one might be that it could work with anything at all up wind. A big ship, a smaller ship's sails, an island, a cliff, a lighthouse on a sea rock, even other sails on the same ship, etc...
To save on processing power, I'd probably just start with the corners, and halt further raycasting if none of those hit.
To specifically answer your question about the bounds of an object as seen from a given angle, there are similar processes here. 1) get the corner vertices 2) get a plane defined from the normal of the wind direction 3) project each vertice as a vector onto the 'wind plane' the resulting vectors should be the shadow profile of the sail in the direction of the wind.
I'd have to experiment with this a bunch to make sure i got the exact method usages right, but I know the answer is in this rough concept.
mmciver, Thanks for the thoughtful response. I have been playing with a sailing simulation so my boys and I can race each other (we have a real sailboat as well). There are many pieces yet to be implemented but the basic sailing mechanics are working.
Blanketing is one of the knottier problems. I am trying to weigh complexity/verisimilitude against simplicity/approximation. As you suggest, I will probably do raycasts from the sail corners/edges to see whether blanketing is even occurring and then perform more raycasts to deter$$anonymous$$e the extent.
The actual blanketing effect does not necessarily pertain to the corners/edges of the sails because the sail area on the very corner/edge is, in most cases, zero. I plan to perform raycasting from a series of points set in from the edge of the sails with those points clustered more closely near the vertical "slice" of sail with the most area.
I may still pursue the volume collider on a parallel track. I understand your description as being the correct analysis, though I'm not sure how to implement all of it but, we'll see what happens.
Your answer
Follow this Question
Related Questions
Get closest point on 2D perimeter using Bounds 2 Answers
TestPlanesAABB Does not work when looking up. -1 Answers
Combining two meshes 0 Answers
How to Move Vertices from a Mesh to a Specific Location 2 Answers
How to use modular geometry 1 Answer