Tank Demo Aiming #117
-
Hello Norbo! I fiddled around with the tank demo, and now I am trying to point a tank's barrel on a target. The problem is it's slightly inaccurate unless the angle between body and barrel equals 0 or 90 degrees: For a test, I placed the sphere of radius 1 in position (3, 3, 3) var targetPosition = new Vector3(3);
var turretBody = Simulation.Bodies.GetBodyReference(playerController.Tank.Turret);
var aimDirection = Vector3.Normalize(targetPosition - turretBody.Pose.Position);
playerController.UpdateMovementAndAim(Simulation, leftTargetSpeedFraction, rightTargetSpeedFraction,
zoom, brake, brake, aimDirection); My first idea was that offset between turret origin and turret anchor causes the problem, but it's not the case. (because this version produces same results:) var targetPosition = new Vector3(3);
var turretBody = Simulation.Bodies.GetBodyReference(playerController.Tank.Turret);
RigidPose.Transform(in playerController.Tank.TurretLocalTurretAnchor,
turretBody.Pose,
out var turretAnchorWorldSpace);
var aimDirection = Vector3.Normalize(targetPosition - turretAnchorWorldSpace);
playerController.UpdateMovementAndAim(Simulation, leftTargetSpeedFraction, rightTargetSpeedFraction,
zoom, brake, brake, aimDirection); What do you think? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
MathHelper.ApproximateAcos, the vectorized acos approximation used by the involved constraints, was a little too approximate. Try out 4b72cd6; it should help. It's still using a very Ye Olde implementation and could be a wee bit better, but the maximum error is about 1000x lower now. I might revamp it again once I can use intrinsics. |
Beta Was this translation helpful? Give feedback.
-
Thank you! Now it's juuuuust perfect. Happy New Year! |
Beta Was this translation helpful? Give feedback.
-
Should be up- I did forget that nuget orders 2.3.0-beta11 as before 2.3.0-beta9, though, so you have to manually select it. Oopsy. |
Beta Was this translation helpful? Give feedback.
MathHelper.ApproximateAcos, the vectorized acos approximation used by the involved constraints, was a little too approximate. Try out 4b72cd6; it should help.
It's still using a very Ye Olde implementation and could be a wee bit better, but the maximum error is about 1000x lower now. I might revamp it again once I can use intrinsics.