Monday, April 29, 2024
HomeGame Developmentunity - Robust detection of ship direction when track splits as an...

unity – Robust detection of ship direction when track splits as an Y shape?


I have a bug with my wrong way indicator when there is a junction on the track.

When I look forward, all is good, but when I look forward to the junction, wrong way appears.

I use the regular approach using dot product:

forward = dot(next section - current section, ship direction) > 0

So I thought that I could do the same with a junction and take the max:

max(dot, dot as above but with junction)

But it’s not convincing, angle at which wrong way shows up is weird, depending of ship position relative to section.

Here’s a picture so you can understand:

enter image description here

  • the triangle is the ship
  • a section is made of quads , here I’ve painted the floor of 3 of them
  • the lines pass through section center points
    • white denotes a regular section
    • magenta means section has a junction
    • blue/orange are junctions (start/inside)

I have the feeling that I could do something with angles between the different sections.

Something like the dot threshold be adjusted according these and ship position.

However, I don’t really know what to do exactly…

Any clues are welcome!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments