Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Correct Third Person Shooter Aiming

Discussion in 'Animation' started by John_Leorid, Jun 17, 2019.

  1. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    646
    By now, I am working on this since two weeks already, just focusing on the problem of third person shooter aiming.
    I have all the movement, all the animations, everything I would need, but somehow it never works as expected.
    I guess the two main approaches are
    ♦ IK
    ♦ setting the spine bone in LateUpdate()
    (some may do it just with an animation blend tree ?)
    ok - in my game, I don't want to use raycast shots, but actual bullets that fly with a certain speed.
    To spawn the bullets, I just want to call Weapon.Shoot() which shoots the bullets out of the muzzle in forward direction. And I want to have absolute precision when shooting and there comes the problem.
    1) when using IK, I have nearly no control over the actual position/rotation of the gun - OnAnimatiorIK LookAtPosition() will just let the character face in a certain direction, I can't control the weapon rotation here to aim exactly at the target point, which leads to bullets not hitting the target I am aiming at.
    2) when setting the spine bone in LateUpdate(), thats actually more of a mathematical problem - because the spine can't just aim at the target, because the weapon has an offset to the spine - the offset changes slightly from frame to frame because of the animation - so I have to get the offset, rotate the offset, apply the offset to the target position and then aim with the spine to the target-rotatedWeaponOffset position. And I can't figure out how to get the correct rotation for the offset.

    Rotating the weapon on it's own, will break the animations, also it will look like the weapon is floating in front of the character.

    Thanks for any advice. For more infos about the mathematical problem, just ask, I'll draw some sketches to illustrate the problem, if overriding the spine rotation is the correct way for precise aiming in tps games.