Ok, so I’ve recently been talking with Kmskazka and have been trying to replicate his targeted projectile with his assistance, but I think I built the base structure of my game too differently from him to be able to replicate it in the same way he is. So, I’ll be posting what I can of my setup here in hopes that someone can help figure out what the issue is.
Ok, so, first off, I move my player around in the world with add movement inputs, basic stuff. Player is a character controller, and it is set to auto possess and is already existing within the level on start.
Next, to set my player’s rotation to be facing the mouse, I have created a new trace channel, created a huge plane at the feet of my player (within its blueprint) and set that plane to react to that trace channel. In the character controller blueprint, I have this setup setting the rotation of the player every tick:
The variable Mouse Loc was created in an attempt to pass on that mouse location from the character controller to my Player, because I spawn the projectiles from my player controller. While I was testing this out, I had attached a print string to get the value that was being put into the Mouse Loc variable, and it seemed to be working.
Next, in my player BP, i created this setup to spawn the projectile slightly above my character’s head:
In this BP, I created a variable that referenced the character controller in order to retrieve the Mouse Loc variable that resides inside it. Unforunately, when I tried doing a print string of what was coming though for that Mouse Loc variable, it always returned 0,0,0 for the vector. This is a point at which it breaks, but I’ll explain my setup further, incase there is a better way to do what I am attempting.
The projectile BP looks like this:
I am fairly certain I understand how it works enough to realize that what it needs is its’ own location and the location of the target it should be traveling to. In anticipation for being able to pass a vector variable to it, I made a Mouse Loc vector variable that was exposed on spawn, so that I could have the player BP pass that info into the projectile at the same time as it was being spawned. Unfortunately, as I am unable to pass a vector to my Player BP, this action was futile.
Those are the problems that I am currently experiencing, however, there are some other issues that exist with this project.
First, when I spawn a projectile (yes, it works, it just travels into the ground almost immediately and disappears), the number of actors goes up, but the number of actors does not go down when it disappears into the ground, leaving me to believe that it is not actually colliding with the ground, even though I set the projectile to be able to collide.
Second is that, even if I were able to pass on the variable of where my mouse is hitting from my player controller, the location is not based on where actual geometry is. What I would need is a line trace that goes from the camera, though the mouse, till it hits geometry, and if it doesn’t hit geometry, then don’t spawn the projectile. I tried doing this within the Projectile BP itself, but I was unable to figure out how to reference the either the mouse or the camera, which resides in the Player BP. Unfortunately, I am not sure how to actually do any of this, even though I know that it needs to be done. I knew of this issue from the start, but my priority was just getting the projectile headed to where I wanted it, and then I would bother with trying to get it to where it SHOULD go.
My third problem is, I am unsure where the best places are to perform these actions. Should I have lots of things in the player BP, or should they be in the character controller BP? Or maybe the projectile should contain most of the nodes for it’s own actions? Info on what would be called something along the lines of “best practices for game programming/visual scripting” or something like that would be nice, because I usually am not sure when I am thinking of creating a new action, if I should put it in an existing BP or if I should create a new BP.
If anyone could help me out with even just a part of this problem, I would really appreciate it. Its been a real love/hate battle with BP, because every answer that I see to problems seems so simple after you see them, but unless you know what needs to be done before hand, and have prepared/created the correct BPs, it becomes incredibly hard to guess your way to the correct answer.