#Raytracing math help?
1 messages · Page 1 of 1 (latest)
Are you sure the draw is accurate?
It says you left the drawing code out in your post.
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
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.
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.
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.
I thought this line took care of the rotation:
but yeah translating positions/rots is killing me here
I think it'd be - global_rotation?
Altho idk a moment where global_rotation would not be the same as the local one.
What could help is relying more on stuff like Vector2.direction_to()
You wouldn't even need to play with angles.
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
The separation MAY need angles yeah.
But that's simpler.
That sounds a lot easier already tho
Your code for splitting them is working flawlessly from what i see. The only issue is rotating them around.
Alright thanks Ill try that out and update