Signed Angle flips randomly
Asked Answered
M

7

0

i'm very new to non visual scripting in general (my third day) i want to get angle between input direction and where character is facing (3d third person game) to play turning animations, so i need it in + and - to determin left and right

$InputDir/InputDirPos.global_translation.signed_angle_to($Mesh/MoveDirPos.global_translation, Vector3.UP)

(meshes are for visualisation) black sphere is for input direction, and white sphere is for where character facing

and finally the problem, when i just walk around in circles angle just randomly switches from + to - and i have no idea why, i tried different sppeds for input and character facing thinking that maybe input just went too far, but nope, it doesn't matter if angle is 5 degree or 90, and it seems to be related to global position

Mullite answered 24/9, 2023 at 5:52 Comment(0)
G
0

Mullite Direction vector from point A to point B is calculated by subtracting the position of B from the position of A.

Grisham answered 25/9, 2023 at 9:43 Comment(0)
G
0

Mullite You need to get the angle between direction vectors, not between positions as you're currently doing.

Grisham answered 24/9, 2023 at 16:7 Comment(0)
M
0

Grisham i'm not sure how to do this, what should i look for in documentations? i'm currently trying to look for a mention of "direction" anywhere there

Mullite answered 25/9, 2023 at 1:28 Comment(0)
G
0

Mullite Direction vector from point A to point B is calculated by subtracting the position of B from the position of A.

Grisham answered 25/9, 2023 at 9:43 Comment(0)
M
0

Grisham thank you so much, it worked, it may be not the best implementation from me but i'm glad it's finally works
and the code i used is this

var Angle = 0
var AngleDir = Vector3.FORWARD
var AngleDir2 = Vector3.FORWARD

func _physics_process(delta):

	AngleDir = $InputDir/InputDirPos.global_translation - $InputDir.global_translation
		
	AngleDir2 = $Mesh/MoveDirPos.global_translation - $Mesh.global_translation
		
	Angle = rad2deg(AngleDir.signed_angle_to(AngleDir2, Vector3.UP))
Mullite answered 25/9, 2023 at 10:20 Comment(0)
B
0

Grisham marking best answer

Bessel answered 25/9, 2023 at 10:46 Comment(0)
B
0

Mullite

Curious if you'd be willing to share what your script looks (looked?) like for this instance? I'm still relatively new to Godot and have been banging my head trying to figure this exact scenario out. Thanks!

Brumal answered 4/1 at 17:44 Comment(0)
M
0

Brumal AngleDir = $InputDir/InputDirPos.global_translation - $InputDir.global_translation literaly just this to get a direction vector

Mullite answered 6/1 at 11:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.