0 votes

Given some 2D objects with corresponding normal vectors I'd like to snap them together such that their normal vectors become opposites. So it'd look something like the following:

enter image description here

enter image description here

Unfortunately I can't get them to stick from all rotations/orientations and am not sure what I'm doing wrong. Hopefully someone can help out. Here's the malfunctioning code:

var my_ang = cnct_joints.mine.normal_angle + cnct_joints.mine.get_global_rotd()
var their_ang = cnct_joints.theirs.normal_angle + cnct_joints.theirs.get_global_rotd()
my_ang -= 180 if abs(round(my_ang)) >= 180 else 0
their_ang -= 180 if abs(round(their_ang)) >= 180 else 0

var diff = my_ang - their_ang
var diff_sign = 1 if my_ang < their_ang else -1
diff -= 180 if abs(round(diff)) >= 180 else 0

set_global_rotd(get_global_rotd() + diff_sign * diff)
in Engine by (693 points)

1 Answer

0 votes
Best answer

I had to change the joint's normal_angle to a normal vector. But this seems to be working! Only took a week or more to figure out...

var start = cnct_joints.mine.normal
var end = -cnct_joints.theirs.normal.rotated(cnct_joints.theirs.get_global_rot())
var ang = start.angle_to(end)
set_global_rot(ang)
by (693 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.