How to shoot projectiles using assault rifle or any weapon?

NitinBan55

New member
I am trying to shoot a projectile whenever I shoot using the assault rifle.
I had attached the "Spawn Projectile" module to the Projectile Modules Group. Assigned it projectile prefab, and all the necessary fields. Yet still the Projectile isn't spawning!
Spawn Projectile.png
(Screenshot taken during gameplay)
 
Hi, I don't think this Tracer prefab is what you need. Take example on the existing Assault Rifle Weapon prefab which uses the Assault Rifle Projectile Prefab, and make sure you're also using the Projectile Shooter module.

Capture d’écran (2377).png

Capture d’écran (2378).png

As I said on the Discord this morning, if you're interested in projectiles generally speaking I've made tutorials for throwable objects, and also thought of making an advanced Shootable Weapon tutorial, with stuff like bullet projectiles and a secondary grenade launcher. If you would be interested in this kind of topic or want to suggest any other, you can lemme know on this page :

http://www.opsive.com/forum/index.php?threads/new-tutorials-for-ucc3.10196/


 
Thank you @Cheo . That helped a lot. Now the projectiles are spawning. But now we ran into another problem.
When we shoot, the projectiles don't move forward relative to the crosshair, they move along an offset direction.
Basically projectiles should follow the crosshair's direction.

Here's a video for reference:

In the above video, when I aim at the Yellow Dummy and shoot, the Projectiles are hitting the Red Dummy. However they should hit the Yellow Dummy to which I am aiming at.

Note:- Just to be clear we are using Cinemachine's Free Look Camera with the Opsive's Integration. And we switched to Third Person Adventure Camera Type, and still got the same glitch.
 
Hi, glad to see you're making progress ! My guess is that you aren't using the Fire In Look Source Direction bool at the top of Projectile Shooter. If it is set to false, it should then follow the weapon's fire point's direction, as it does in your video. Lemme know if setting this value to true fixes the problem !
 
Hi @Cheo . Thanks for the suggestion. We already had the Fire In Look Source Direction bool set to True, yet still it is not working as intended. We tried setting the bool true/false and still get the same glitch. We even looked around other camera view types to see what's happening, and found out that cinemachine view type has this problem. We will need Cinemachine for our further mechanics. So could you provide us with helpful response?
Thank You.
 
If it's just Cinemachine that's having the problem it's likely related to the Cinemachine LookDirection method. I will add this to my list of things to look at.
 
Hi @Justin . We took your point into consideration and edited the CinemachineViewType.cs script. We added some lines of code in the LookDirection function. And its working perfectly. The projectile now moves to the crosshair's direction & position.
We took the ThirdPerson.cs script as reference and added some lines from this script's LookDirection function.

Here's the code that we changed:

(P.S: I have provided the script in next comment)
public abstract class CinemachineViewType : ViewType { ... /// <summary> /// Returns the direction that the character is looking. /// </summary> /// <param name="lookPosition">The position that the character is looking from.</param> /// <param name="characterLookDirection">Is the character look direction being retrieved?</param> /// <param name="layerMask">The LayerMask value of the objects that the look direction can hit.</param> /// <param name="includeRecoil">Should recoil be included in the look direction?</param> /// <param name="includeMovementSpread">Should the movement spread be included in the look direction?</param> /// <returns>The direction that the character is looking.</returns> public override Vector3 LookDirection(Vector3 lookPosition, bool characterLookDirection, int layerMask, bool includeRecoil, bool includeMovementSpread) { //Custom Code var collisionEnabled = m_CharacterLocomotion.CollisionLayerEnabled; m_CharacterLocomotion.EnableColliderCollisionLayer(false); //End if (m_UseCharacterLookDirection) { return (CharacterRotation * Vector3.forward); } var crosshairsDeltaRotation = characterLookDirection ? Quaternion.identity : GetCrosshairsDeltaRotation(); //return (m_Brain.CurrentCameraState.FinalOrientation * crosshairsDeltaRotation) * Vector3.forward; //Custom Code var rotation = m_Brain.CurrentCameraState.FinalOrientation * crosshairsDeltaRotation; Vector3 hitPoint; if (Physics.Raycast(m_Transform.position, rotation * Vector3.forward, out var hit, m_LookDirectionDistance, layerMask, QueryTriggerInteraction.Ignore)) { hitPoint = hit.point; } else { var offset = Vector3.zero; offset.Set(0, 0, m_LookDirectionDistance); hitPoint = MathUtility.TransformPoint(m_Transform.position, rotation, offset); } m_CharacterLocomotion.EnableColliderCollisionLayer(collisionEnabled); var direction = (hitPoint - lookPosition).normalized; return direction; //End } ... }

Here's the video after the code fix:
(Now the projectile spawns in the crosshair's direction, where we are aiming)

But now we are facing another issue. When we aim, the crosshair points down for some reason. This doesn't happen with the Adventure View Type. Only happens with Cinemachine View Type camera. Also, there's some weird glitch that occurs when we aim at the Dummy (Boxing Joe).

Here's a video for reference:
(In the above video, when we aim, the crosshair's position changes and goes down, and resets as we un-aim.
And when we aim at the dummy camera rotates around weirdly)

Some help on this would be appreciated.

Thank You.
 
Last edited:
Glad you are making progress. That looks like a quaternion rotation error. If you debug the returned rotation my guess is that you'll see the value have a dramatic change each frame.
 
We figured out the issue @Justin . Basically the rotation values were changing when we aim/un-aim, as you said. We found out that when you are using a Cinemachine Third Person View Type, when you aim, the Main Camera's Rotation value for X changes.
For Example:- Before aiming lets say the values is 6.50, and when you aim, the value changes to 8.70 or something. And that is happening because we set the Aim in the Rigs (Top, Middle & Bottom) of the Cinemachine to Composer.
So you just need to set it to Hard Look At, and the issue is solved! You can give the Look At Override target as well if you want.

Here's a reference of the Cinemachine Free Look Camera's settings:

Crosshair Aim Fix 1.jpg
Crosshair Aim Fix 2.pngCrosshair Aim Fix 3.png
 
Top