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"

1st person shoot in camera direction + varying power

Hi there,

So I have two parts to this: 1> I want to be able to shoot my projectile (a destructible cannon-ball style projectile) using the direction and angle that my camera is facing,

What I have so far is it will shoot in the right direction but always at a set height - so it ignores the elevation of my camera to a large extent.

alt text

This is what I have so far, which spawns a projectile, then adds an impulse to it (Bullet Velocity). This leads me on to part 2:

2> How do I make it so I keep my button pressed and it 'charges' up the power within a definable range ( possibly with a cap). I have a variable (Bullet Velocity) but I'm not sure how to use the mouse button press to raise this value over time.

Any help on both these matters would be appreciated, with pics if you can (I'm thick, and pretty visual).

Thanks so much


Product Version: Not Selected
spawnproj.png (283.4 kB)
more ▼

asked Mar 09 '15 at 08:26 PM in Blueprint Scripting

avatar image

42 10 17 21

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

In order to charge the power of your projectile, I would recommend moving the fire functionality from Pressed to Released. That way you can set up your Pressed event to start charging your power. I would create a bool in the character blueprint (which I assume this is) to determine whether power should be charging or not. I would also make variables (floats) for Launch Power (Bullet Velocity in your case) and MAX_LAUNCH_POWER, if you want a maximum. Then, in your Event Tick function you can charge up the power (to the max value if you like) whenever the button is pressed.

For example, detecting a Left Mouse Button input:

alt text

When the input is activated, bLeftMouseDown is set to true. When the button is released it is set to false, then the Fire event is called.

In the Event Tick you just need to check whether bLeftMouseDown is true or false:

alt text

If it is true, add whatever value you want to your Power (I called it Launch Power, your example was Bullet Velocity). In this case I just added DeltaSeconds, but you can make it anything. Where I have the Fire event you can just put what you already have as the Fire functionality.

As for the other problem, if you want to use the camera to determine the projectile's spawn location, use that instead of Actor Location. If your character has a camera component, you can use the Get World Rotation and Get World Location functions:

alt text

Hope that helps!

leftmouseevent.png (85.1 kB)
tickevent.png (100.1 kB)
more ▼

answered Mar 09 '15 at 10:08 PM

avatar image

471 7 9 32

avatar image dazuk1978 Mar 09 '15 at 11:38 PM

Hey thanks for that, the Power stuff worked a treat! Well I seemed to have to find a way to reset the Bullet Velocity back to zero in between shots as it seemed to remember the previous shot otherwise... but I think I got that.

The second bit though doesn't work for me. It's not so much the spawn location that's the problem, it's that the initial direction of the impulse for the cannon ball is straight out from the camera, rather than where I'm looking with the camera. So it pays no heed to the elevation (up or down) facing of the camera and I want it to factor that in so the player can look up at say a 45 degree angle and shoot a cannon ball up in the air but he'll need to compensate for the steeper angle with some extra power! I think that's clear? Whatever I do seems to make it worse. Any ideas?


avatar image dazuk1978 Mar 10 '15 at 12:06 AM

Okay, scratch that. I figured it out and it works great now :)

I do have another question though if you can indulge me please?

When I spawn the projectile, I want to spawn a camera that follows the projectile on it's journey to the target, then after the projectile is destroyed I destroy the cam and go back to the standard first person camera. Any ideas?


avatar image ZombieKemist Mar 10 '15 at 04:30 PM

I will look into that when I get some time. My initial guess is it will have to use the Player Controller, since that is where a lot of the camera functionality is.

avatar image dazuk1978 Mar 11 '15 at 10:12 AM

That'd be appreciated. I have started another thread about this particular problem so I can resolve the rest of it that you helped me with! Thanks - link to new thread: https://answers.unrealengine.com/questions/189162/swap-camera-onto-projectile-temporarily.html


(comments are locked)
10|2000 characters needed characters left
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