- Home /
Shell Drop and Aiming
Hello everyone, I am currently in the process of developing a game which involves shore guns firing at targets over a long distance. These guns can already rotate towards a clamped angle and elevate their guns to look at a target. However, I intend to have a form of non-linear "bullet drop" for the shells, and thus the guns will have to aim higher so the shell will actually drop on the target (dispersion I have already taken care of). So here are my issues:
I'm not sure how to give my shells a parabolic drop (no other influences, ex. wind), and
How my guns can compensate for the drop (Important: my batteries should elevate their guns to compensate, not reduce velocity).
Any thoughts or comments would be greatly appreciated!
Edit: My projectiles and targets are both rigidbodies.
Correction: I am intending to create a simple parabolic drop for projectiles, with varying velocities. I have also seen a snippet of code allowing the guns to aim higher to compensate for drop, but I am not sure how to implement it.
aimPosition = targetPosition + Vector.up * dropCurve.Evaluate( distanceToTarget );
Thanks!
Answer by incorrect · Jun 14, 2018 at 06:11 PM
If your projectiles are rigidbodies and not marked as kinematic, it means they will be affected by the gravity and will naturally fall down causing that parabolic trajectory. Also you can apply a vertical force to them in FixedUpdate to create that curve. The implementation really depends on the desired behaviour.
And about the second part of your question: you literally have to calculate trajectory before the shot taking into account the time of projectile's travel to target and the parabolic fall.
Could you suggest any sort of equation or how I would calculate this? (I'm still a bit of a newcomer to unity :D)
I don't have any equation for you. You should figure it out yourself. And it's not Unity-specific, it's general math, so be ready to go head-first dive into how it works.
Additionally, would the projectile need it's own script, or would the gun do the work?
You can make gun's script do all the work, but that will result in many problems you will face in future development, if there will be any. Read about the concepts of OOP, it will help you to understand how things work.
Sorry, but I'm not sure how a OOP relates to ai$$anonymous$$g and parabolas...
Your answer
Follow this Question
Related Questions
AI rigidboy aiming 0 Answers
AI Turret Aiming 2 Answers
Thief Car AI for 3D Game 0 Answers
2D 360 degress platformer example needed 0 Answers
How to get rid of jumpy collisions? 1 Answer