- Home /
How do I choose the Rotation of an Auto Aim Turret using ballistic trajectory and the muzzle as starting point?
I'm currently working on a school project and I want to shoot a projectile from a auto-aiming spherical turret with a muzzle at a target. I already got the right formulas for the trajectory from the center of the turret to the target and it's working fine so far. The Turret's (and therefore the muzzle's) rotation is set to match the initial velocity of the projectile.
But it still looks wrong, because the projectile is not released from the muzzle. Instead it comes out from under the barrel and of course it gets worse when the trajectory is higher.
What I want to do is set the muzzle as the origin of the projectile trajectory, so that the rotation of the turret/muzzle aligns with the initial velocity of the projectile. The Rotation should not be constrained in any way and the speed of the bullet should be fixed. I don't use air resistance yet, so acceleration and deceleration can be ignored.
Sorry for the beautiful Paint image:
So how can I get the right turret rotation and therefore the muzzle position? Has anyone encountered this problem? Can anyone help me please?
Answer by suark · Nov 27, 2015 at 03:11 PM
You need to make the bullet child of the muzzle. This way it will move together.
So my Bullet now gets instantiated at the position and rotation of an empty object that is a child of the muzzle which again is a child of the turret. Therefore it flies out of the tip. Thanks!!
But the rest still does not work the way I want it to...
Answer by robusto · Nov 28, 2015 at 02:17 AM
Don't use the center of the turret as the starting point, use the position of the muzzle's tip or end of the barrel's position (where the projectile comes out). The starting trajectory of the projectile should be the same trajectory of the barrel so when the projectile comes out, it is straight out of the barrel and will fall. This should make it look realistic.
That is working fine now, thanks! But the actual problem still remains. Let me explain my approach. 1. A target triggers the collider of the turret. 2. The turret rotates around the y-axis until it faces the targets postion. 3. The trajectory gets calculated and the turret (or maybe only the barrel) rotates around its x-axis until it points at the right angle. 4. The turret fires.
$$anonymous$$y problem lies in point 3. How do I get the right angle with the given target position, gravity at 9.81Nm and predefined bulletspeed?
Or am I just complicating things here and there is an easier way to both hit the target and get a accurate barrel alignment?
$$anonymous$$aybe a friend of $$anonymous$$e who studies automotive engineering can calculate this. I will keep you all informed and hopefully we can solve this issue!!!