x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Need help shooting projectiles at the center of the screen.

Hello, I am currently trying to get my projectiles straight when aiming. After looking at other answers, I tried to do what others have said but still comes out off regardless if the character is crouching, looking up, or if the camera has switched sides.

Right now, my code looks like this (Muzzle is where the bullets are actually spawned at in my c++ file): alt text alt text

Which yields results like this (And even more off when crouching or with the camera switched: alt text

Can anyone give me any pointers on what I am doing wrong or if I am missing something? Any Help will be appreciated.

Product Version: UE 4.9
Tags:
2016-01-22 (1).png (117.9 kB)
2016-01-22.png (65.2 kB)
more ▼

asked Jan 22 '16 at 04:46 PM in Blueprint Scripting

avatar image

D3ATH95
46 9 12 16

avatar image D3ATH95 Jan 22 '16 at 04:53 PM

Edit: I forgot to mention that from what I read, the best way to go about it was to do a LineTrace where the camera is pointing at, normalize the impact point, and that should be the value for the muzzle if you want to shoot more towards the center.

avatar image Matthew J Jan 22 '16 at 06:07 PM

Hello D3ATH95,

I'm not quite I understand how you're using the Muzzle variable. You say that you're using the Muzzle as the spawn point for the projectiles but in the second screenshot it also seems like you're setting Muzzle to be where the bullet ends up. Also, could you provide the code file (you can just upload the file itself instead of snippets) where the spawning occurs?

avatar image D3ATH95 Jan 22 '16 at 06:47 PM

It's possible I may be using muzzle wrong. And I have been working on this for the past two hours, so the code keeps changing and it originally didn't look like this. This was just after of two hours of trying different combinations to get it to work.

And it's not letting me upload the C++ file, but here is the code:

 void ABaseWeapon::FireWeapon()
 {
     if (bCanFire == true)
     {
 
         Heat += (10 - HeatSupression); 
 
         if (Heat >= 100)
             OverHeatCD();
 
         else
             CDWeapon();
 
         const FRotator SpawnRotation = GetActorRotation();
         const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(Muzzle);
 
         UWorld* const World = GetWorld();
         if (World != NULL)
         {
             GunMesh->PlayAnimation(FireAnim, false);
             World->SpawnActor<ABaseBullet>(Bullet, SpawnLocation, SpawnRotation);
         }
 
         //World->GetTimerManager().SetTimer(AutoTimer, this, &ABaseWeapon::FireWeapon, AutoTime, false); Temporaly set to false since automatic fire is controlled by blueprint.
     }
 
     else
         StopFiring();
 }
avatar image Matthew J Jan 22 '16 at 06:59 PM

Have you tried shooting, immediately pausing, and unpossessing the character to make sure that the bullet is coming from the correct spot? The reason I mention this is because your calculation for the Spawn Location. I would suggest using a Socket that you place at the end of the barrel for the gun and use that Socket's position as a reference for spawning the bullet.

When is the line trace called in relation to the FireWeapon button? Is it before or after? This matters due to how Muzzle is being used/set and could be causing some issues.

avatar image D3ATH95 Jan 22 '16 at 07:15 PM

Tried unpossessing, wasn't leaving the right spot. I tried spawning from a socket, which while it does fix the problem of the character sometimes getting shot by his own gun, I still have the issue of having my aim off, I'm still trying to figure how to use the muzzle vector now after that calculation.

And after, The fire button is handled in the Player Characters BP, which then sends a message to the gun the player currently has. Once the gun receives the message, before it actually fires, there's a blueprint function that does a line trace to whatever the camera is pointing at. Then it fires. It then does an Automatic fire loop that keeps calling the event Pull Trigger, repeating the process before it overheats.

avatar image Matthew J Jan 22 '16 at 07:28 PM

I didn't think about this before for some reason, but it could be the line trace itself that is hitting the wrong spot. Could you try changing the Draw Debug Type on the Line Trace node to Persistent? It'll show a red box where it's hitting the wall so you can see if it is hitting the right spot.

Going into the weekend so won't be able to respond until next week at this point, but I'll be sure to keep looking into it.

avatar image D3ATH95 Jan 22 '16 at 07:31 PM

Tried it before, was hitting the right spot. I'm think it might have something to do with camera angle that might be causing it to go off center. I remember seeing a piece of code before that does a line trace exactly at the center of the screen by getting the screen position, but now I can't find it anymore.

avatar image Matthew J Jan 26 '16 at 06:41 PM

Would it be possible to get a copy of the project or a sample that has the shooting logic set up inside of it to tinker with? It can be private if you wish by sending a link to it via a private message on our forums. Here is a link to my profile.

Otherwise, I suggest setting up some print strings or log messages to show you all of the calculations that are going on to see where the unexpected result is coming from.

avatar image Tensa_Zangetsu Jan 22 '16 at 06:38 PM

Hi, What about maxRange?

avatar image D3ATH95 Jan 22 '16 at 06:55 PM

Max range doesn't effect the bullets trajectory or centerness. Only how far it'll do the trace. Even still, it's not centered regardless if I aim at something relatively close to the player.

avatar image Ryan Darcey Jan 22 '16 at 10:29 PM

This actually looks correct to me. Welcome to 3rd person cameras! It's impossible to get bullets to line up with your reticle in every situation, at every distance. Even in a first person shooter, you'll find that projectiles are usually fired from the camera location, not the weapon muzzle (though muzzle flash will obviously play on the muzzle).

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

We haven't heard from you in a while, D3ATH95. Are you still having problems with lining this up? If so, would it be possible to provide a copy of the project so that I can take a look at the problem first hand? In the meantime, I'll be marking this as resolved for tracking purposes.

more ▼

answered Feb 08 '16 at 07:57 PM

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question