- Home /
Procedural character aiming
I have a character (in 3rd person) aiming down the sight of their gun. I'm shooting projectiles straight out of the end of the gun, but it doesn't match up with the crosshair.
What I'm trying to do is make it aim at the crosshair at any distance (at the hit point of a raycast, or the end of the ray if nothing is hit), so that whether you're aiming at something near or far, the character will adjust their aim to always hit the center of the crosshair.
I've tried a few different things, such as having the right arm rotation (the left arm/gun/head follow this transform's rotations) linked to an empty gameobject which looks at the correct point; I've also tried manually adding to the rotation through scripting but this is a far from ideal solution as it needs to be adjusted for every individual (aiming) animation present and seems to be rather inaccurate anyway.
I was wondering if anyone had any thoughts or experience on this. Perhaps (hopefully) I am overlooking something simple that I could do to resolve this.
Is this am FPS? Generally they don't move the guns rotation to aim 'exactly' at where the bullet will collide with an object. Ins$$anonymous$$d the gun just looks like it's ai$$anonymous$$g toward the center of the screen then you adjust the direction of the bullet based on the picking/raycasting method you mentioned.
EDIT: Stupid question, your question states that it's a 3rd person game. $$anonymous$$y mistake. Apologies.
Can you post the code for the ai$$anonymous$$g you use? After looking at it we might be more helpful...
Sorry for the delayed response, was out of town. The code is dogzer's (search for dogzer on the asset store and you'll find his free character with ai$$anonymous$$g scripts).
Answer by everygamer · Aug 23, 2012 at 12:50 PM
Sounds to me that if your in a 3rd person perspective your not looking right down the barrel of the gun..This implies there is an angle between your line of sight and where the bullet is going..The cross hairs are likely stationary to your view and set a specific distance from your character. So mattering how far away and there relative position to you, your target would change the angle and where the cross hair would need to be placed to line up with the shot.
What this means is you would need to constantly calculate and move your crosshairs to correct the angle.
This is why shooters are 1st person perspective, it cuts out that angle and makes the line of sight line up with the line the bullets travel, and or at least minimizes it by keeping he angle on the y-axis and they make a sliht adjustment to the cross hairs position.
The other thing you could look at doing is pick a point in space where the crosshair/bullets will intersect. This would keep the cross hair fixed, and different guns could have different effective ranges. It would make it most accurate in specific situations and less in others.
Sorry for the delayed response, I was out of town. But yeah, doing it with the scripts I was using (modified version of dogzer's soldier aim script) has produced pretty undesirable results. The character does aim at the crosshair properly at any distance, however there are a few other issues that arise, and I know that fixing them is going to take longer than this kind of setup is even worth. So I think what I'm going to do is just use pre-animated aim poses and blend between them. It will be a lot faster to set up and much more smooth looking. As far as the I$$anonymous$$, I don't even need an I$$anonymous$$ in Unity anyway, I can just have one in $$anonymous$$aya and then bake the animation and of course the I$$anonymous$$'s influence on the animation comes through.
Answer by create3dgames · Aug 31, 2012 at 07:27 PM
Check out Unity's 3rd person shooter example or the Bootcamp demo.
Your answer
![](https://koobas.hobune.stream/wayback/20220613080041im_/https://answers.unity.com/themes/thub/images/avi.jpg)