#Raytracing math help?

1 messages · Page 1 of 1 (latest)

verbal monolith
#

The rays are not at a child at all. Im using the query to calculate them manually. Then drawing what they would look like latern on with the same startting point and end point. Sorry if its confusing

worn oracle
#

Are you sure the draw is accurate?

#

It says you left the drawing code out in your post.

verbal monolith
#

Heres the rest. It uses the same start point and end point so I think the visual should match the actual result of the colliders: discord doesnt let me write it all at once

#

actually ill just upload the gd file

worn oracle
#

One thing to keep in mind is that drawing is local.
So if you try to use the same logic from the checks for the drawing (which works in global coordinates as everything physics related does), it'll be off.

You can use Node2D.to_local() to translate global coordinates.

#

As for what is wrong exactly, it is kind of confusing.
Dealing with translation of positions is always complicated.

#

Here you have to account for the inherited position, plus the inherited rotation, plus how it correlates to the global one, etc.

verbal monolith
#

would this translate the cordinates correctly for drawing?

var start = ray["start"]-global_position
var end = ray["end"]-global_position
#

Yeah I'm not sure how to implement it correcly.

worn oracle
#

This only fixes the position. You're also dealing with rotation here.

#

to_local() is the simplest solution.

#

I say solution, but i barely understand what is going on tbh.
Whenever i work in stuff like this, i feel even more lost than with shaders.

verbal monolith
#

I thought this line took care of the rotation:

but yeah translating positions/rots is killing me here

worn oracle
#

I think it'd be - global_rotation?
Altho idk a moment where global_rotation would not be the same as the local one.

verbal monolith
#
  • here just made it so the endpoint is always on the right now
#

"-"

worn oracle
#

What could help is relying more on stuff like Vector2.direction_to()

#

You wouldn't even need to play with angles.

verbal monolith
#

So like using direction_to( to the eye offset so it maches its angle)? But how would I avoid using angles to increase the distance of that ray

worn oracle
#

The separation MAY need angles yeah.
But that's simpler.

verbal monolith
#

That sounds a lot easier already tho

worn oracle
#

Your code for splitting them is working flawlessly from what i see. The only issue is rotating them around.

verbal monolith
#

Alright thanks Ill try that out and update