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.

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

Daz

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:

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:

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:

33348-cameralocandrot.png

Hope that helps!

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?

Thx

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

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?

Thanks

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.

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:

Thx