- Home /
How to ensure multiple weapons fire towards the same target?
I have a shooting system that uses projectiles instead of raycasting due to specific game requirements. When firing one weapon it is quite simple to display a reticle for where this weapon's projectile is headed; this is also the case when two of the same weapons are being dual fired since they both have the same effective range. What I can't seem to figure out is how to handle dual wielding different weapons, i.e. weapons that have a different effective range since after leaving their respective weapon barrels, the two projectiles have a different target to aim for, don't they?
Since the weapon system uses projectiles which are physically fired from each barrel (and have a trail clearly showing their firing origin), as far as I understand I cannot simply fire both weapons from the center in a straight line since this would be visually obvious. I am also against the idea of using a separate reticle for each weapon since this is not how dual wielding is commonly handled in modern shooting games. So I am wondering how can weapons of differing effective ranges fire towards the same target so that only one reticle can be used? Should a different target be used for each weapon, or should they both share the same target?
Answer by Cherno · Jan 07, 2015 at 04:53 PM
I would do it like this:
Cast a ray from the camera forward. Then, for each weapon:
Declare a Vector3 that acts as the gun's aiming point. If the distance between the camera and the raycast's hit.point is bigger than the gun's max range (or if there is no RC hit at all), the aiming point is camera.transform.forward * max range. Else, the aiming point is the hit.point. After you have your aiming point, just rotate the gun so it looks directly at it, using Transform.LookAt or similar. For very close points, you might also want to slide the gun towards the center bottom of the screen.
That sounds like a good idea. Since this is a system for a 3rd person game I will have to be careful how much I rotate and move the guns around so that it isn't so obvious from over the character's shoulder etc. I suppose what I could do as well is make all of the bullets/projectiles home in on the center target; even though this would stop the bullets from travelling in a completely straight line, over the range that they will be fired this shouldn't be that noticeable and it should be easier to achieve precision this way.
For third person, maybe casting the ray from the model's head (using the head bone as the origin, for example) will be better than from the camera. As for rotating the guns, since 3rd person view uses no dedicated view models, you will probably achieve the best results with a simple I$$anonymous$$ solution so your guns and the arms and hands holding them follow the target position.
Your answer
Follow this Question
Related Questions
Aiming in the direction of cursor in third person. 2 Answers
Enemy Aims at Player's Current Position 1 Answer
Shoot bullet and control its speed 1 Answer
fire towards mouse pointer 1 Answer
target tracking with lead time 1 Answer