im trying to do a little rotation trick, but am having a hard time coming up with a proper solution. hoping someone here may be able to chime in and tell me where im being a goofball :)
my goal is this... i have two entities which must always face each other. locking them to always directly facing each other is easy (PointEntity) but doesnt have the desired effect im looking for. what i would like to do is force the nodes to look at each other, but can vary their look angle by 45 deg on either side of directly looking at each other. my algorithm has been this:
1) get current entity1 rotation
2) pointentity to entity2 and get direct facing rotation
3) if the difference between current and direct is > my allowed angle difference, adjust current rotation to allowed angle degs off center
i may need to provide a working example, but here is my code. it works well except when the node crosses the 179/-179 border. then the calculation goes awry and jumps the rotation to the opposite allowed offset. in this code, nodes are essentially TEntity objects and rotations are only done around the Y axis.
any thoughts would be much appreciated :)
my goal is this... i have two entities which must always face each other. locking them to always directly facing each other is easy (PointEntity) but doesnt have the desired effect im looking for. what i would like to do is force the nodes to look at each other, but can vary their look angle by 45 deg on either side of directly looking at each other. my algorithm has been this:
1) get current entity1 rotation
2) pointentity to entity2 and get direct facing rotation
3) if the difference between current and direct is > my allowed angle difference, adjust current rotation to allowed angle degs off center
i may need to provide a working example, but here is my code. it works well except when the node crosses the 179/-179 border. then the calculation goes awry and jumps the rotation to the opposite allowed offset. in this code, nodes are essentially TEntity objects and rotations are only done around the Y axis.
Local current_rot:Vector3df = node1.GetRotation(True) PointEntity(node1.GetNodeObject(), node2.GetNodeObject()) Local direct_rot:Vector3df = node1.GetRotation(True) If Abs(current_angle) > angle_limit Then Local diff:Float = (Abs(current_angle) - angle_limit) Local angle_adjust:Float If current_angle < 0 Then angle_adjust = direct_rot.GetY() - angle_limit Else angle_adjust = direct_rot.GetY() + angle_limit current_rot.SetY(angle_adjust) EndIf node1.SetRotation(current_rot, True)
any thoughts would be much appreciated :)