1st person shoot in camera direction + varying power
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
asked Mar 09 '15 at 08:26 PM in Blueprint Scripting
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:
Hope that helps!
answered Mar 09 '15 at 10:08 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here