i'm making a 3d stealth game. i have an enemy with a raycast always pointing towards the player's head. i want to compare the raycast's rotation with the enemy's overall rotation to determine if the player is within the enemy's view cone. the issue is, i want to ignore the y axis, i don't want the calculation to be affected by height. if i do distance_to with the vector3's, it will factor in height. what's an efficient way to avoid this?
#how to treat a vector3 as a vector2 while using distance_to
61 messages · Page 1 of 1 (latest)
You can try to set y axis from both vector to 0 then calculate the distance
and just change it back afterwards?
So you have a view cone and a raycast that always point to player, they are different nodes?
I've also used a method where I make new Vector2's from the axes I care about, use the functions I want, then discard the Vector2's
Though if you just care about distance, you can easily calculate that yourself without using the vector function
i think i was wrong saying i don't care about the y rotation, i keep getting the coordinates mixed up
i only want to compare the y
i don't have a tangible view cone anywhere, i want to just do it with math
and i want it to be a wedge, not a cone
this works
it just seems inefficient to have these extra vectors
global_rotation.distance_to(view_turret.global_rotation) looks wrong
why
im trying to compare the angle of the enemy's root node with the angle of a child it has that points towards the player
i'm not using that specific code anymore regardless
but it did what i expected
I guess distance_to should be used to measure position distance, so I always use on position or global_position, not rotation
Godot Engine documentation
A 3D vector using floating-point coordinates. Description: A 3-element structure that can be used to represent 3D coordinates or any other triplet of numeric values. It uses floating-point coordina...
link to vector3 distance_to method
I don't know how to explain, but looks weird to use distance_to when the Vector3 is a rotation
It feels like you should to use angle_to()
seems to do the same thing
i tried it
just wider view angle
nvm, the number i enter doesn't seem to affect it
is there any benefit to using this over the other one
since the other one worked
I don't think so
i did figure out that one of my extra vectors was redundant since the enemy only rotates on the y axis, i'm going with this
still feels excessive to make a whole other vector3 just to omit something
hold on..
im mostly concerned about it since a bunch of different objects will be running this every frame
Can't you just do
abs(view_turret.global_rotation.y - global_rotation.y)
Since you just want to know the difference in y rotation
yeah that works here
but i have sort of an instinct not to subtract rotations like that because they can loop around, like in gamemaker i would get issues if one was 350 and another was 10, they'd think they're 340 apart and not 20 apart
isn't that going to be an issue?
(i'm still pretty new to godot)
i was excited about vectors because it seemed like it would avoid that stuff
That can be an issue (I've encountered it before), but you'd get the same problem using .distance_to()
There are workarounds
Or you could try to explore Quaternions (They're worth it)
you're saying that using distance_to on a vector will have that issue? i thought one of the most important purposes of vectors and that method is to get around that
Vectors are just bundles of numbers. They wrap around rotations the same way.
Quaternions are what avoids all the common pitfalls.
i have created something beautiful while testing
alright, i'll learn it
weeeeeeeeeee
"You spin me right round"
it's weird that distance_to even exists, i feel like it should never be used if it has this issue
i tested it and just can't believe that it happens
like i can't imagine a situation where i'd be ok with using that method
It's meant to be used on positions.
For positions, it's perfect
It really isn't meant for rotations.
Vectors are mostly used for positions, Quaternions are used for rotations internally, the Vector rotations are just there for the benefit of the developer, to give a simple way to interact with rotations, which works for a good amount of use cases.
ic