#Setting rotation to acos breaks everything

11 messages · Page 1 of 1 (latest)

delicate solstice
#

Hey, I have a characterbody3d with AI, and this prints perfectly as the body moves around:
acos(velocity.x / velocity.z)
but if i try:
rotation.y = acos(velocity.x / velocity.z)
it somehow breaks the entire object's physics/AI, anyone know why that is?
Setting rotation.y to other things works fine by the way, the problem only comes up with inverse trig

high gate
craggy totem
#

in my experience using the rotation and angle functions built into the Vector-Type are simpler and more performant than using the trigonometric functions directly. I'm guessing that you want to rotate the body into the direction it's moving on the xz-Plane. Putting the x and z components of the velocity into a Vector2 and then calling Vector2.angle() should do the same, while considering edge cases like one of the components being 0.

delicate solstice
#

Why avoid trig? I actually used a ton of trig for the directional knockback system :o
But yeah exactly, this is supposed to make it look in the direction it's moving

delicate solstice
# craggy totem in my experience using the rotation and angle functions built into the Vector-Ty...

I see. I didn't even know you could use Vector2s in a 3d scene, i don't know why i just didn't think of that. I also didnt know about the vector.angle function, that's really convenient here. You're exactly right on the intended function and that does sound a lot simpler, so ill give that a shot. That also opens up a lot of possiblities that i can use 2d vectors like this.

To be honest I'm still curious and confused about the trig attempt, i cant believe every part of the physics breaks from that simple line, especially since the trig works fine when not set to rotation

craggy totem
#

One thing i just remembered is the fact that acos like all invers trigonometric functions can only output in a range of 180°, not the full 360°. You have to check the quadrants your vector lies in and add to the result accordingly, which is what the angle() method of vectors does. So there definitely was a problem with your approach no matter if you set the rotation or not, you probably just noticed because of that.

delicate solstice
craggy totem
twin steppe
#

if it broke the AI, that means the AI relied on the body not rotating. a simple fix would be only rotating the sprite and not the whole node, though i dont know if you tried that yet

delicate solstice
delicate solstice