Creating 3D Slingshot, need help!

Hi, first of all, I’d like to say that I’m practically clueless about programming and coding, but thanks to Blueprints, i managed to build some framework for small prototype. However, I recently hit a wall, and would like some one experienced to guide me through it.

Basically, what I’m trying to do is to create a 3D Slingshot, think Angry Birds but in 3D (With the camera behind the Slingshot), with the controls being tied to mouse/touch (pulling the slingshot rubberband and releasing it). However, I have no idea how to approach this. Can anyone with more experience point me to the right direction? I know I have to convert the mouse location to world space, but beyond that I can’t figure out a way to create the Slingshot logic. :frowning:

Help will be greatly appreciated.

If you go into the content examples that you can download from the learn tab you will find they have a bunch of blueprints in there in their physics and blueprint communication maps that show how to use mouse input to drag things across the screen. Thats pretty much exactly what you want for your code side of things.

But a slingshot fires a projectile in the opposite direction of the pull, and the velocity is determined by how far you pull the rubberband, I don’t think all of this is in the content examples.

You may try something similar to this.

I’ve already seen that link, but I didn’t understand much of it. First, what’s the “Fire Splitter” function? Secondly, he is trying to make it on a 2D Plane, while I’m aiming for 3D.

I made a bow and arrow prototype. Mine was for VR so it was a bit different but maybe my thought process will help you.

I just did an approximation for the pull strength and velocity. But then based on a few test shots I calibrated my fudged math to shoot an arrow at around the same speed you can with most bows in real life.

Here is what I did:

When player starts pulling back, save the initial grab location
As the player moves back their hand, calculate the length between the original and new position. Call this PullDist or something

I divide Pulldist by the maximum length to normalize it, and then just did a power of 2 (which is like PullDist * PullDist). Then I had a nice 0-1 pull strength value with an exponential curve. Probably not 100% accurate but it feels pretty good since arrows with a less than full pull will not go near as fast.

Then to fire the arrow I just set linear velocity, and I set that as a vector with a number along X. So the velocity vector was VelocityPullDistPullDist

The value of that velocity was what I tweaked to get realistic arrow speeds. Basically I debugged that by having the “arrow” projectile BP print debug messages whenever it hit something. I converted that number to feet per second and then I just fiddled with my velocity multiplier vector until I got the desired speeds. Interestingly after doing that, my accuracy is almost the same in VR as in real life.

in my prototype, the string was just debug lines. I had a vector location that was set to be the hand grab location, and then on release I played a sinewave with a timeline to cause the string to bounce a little bit. So no physics but even that little fake string bounce made it feel immersive.

for non-VR this is even easier. You just need to make the user hold a button to pull the sling and then play with making the velocity curve exponential like above. Lots of ways to approach it, I would probably use timelines at first for simplicity.

Can you please post your Blueprint graphs? It’s hard to follow through words (Like I said, I’m practically clueless in coding). Seeing Blueprint examples will definitely help.

I will try but it will be a while. Sadly I had to delete the engine folder from that build since I am always running out of hard drive space. And even now I have a bunch of stuff I need to move around but I don’t have time. So one day soon I will get my hard drive space issues sorted and then I will try to load it up.

I do have a new drive with space but the problem is I have to basically not work for several hours while I move a few builds over to that drive, and it seems like its always hard to find that time since I move my portable drive around so much.

Hi MohdNadjib760,

I created a 3d slingshot project. Here is how it operates. Press D to drop a ball. You click and hold, then pull away to strengthen the power. Release to shoot! This along the lines of what you were looking for?

https://file.ac/GAKZdY1MdwA/

i need this, but the file is gone.

Okay so it stumbled on this while searching for a way to make a 3d sling shot and I found nothing so I made my own and am leaving it here in hopes that it helps others.


the first photo shows whats happening in my event graph, the actual “firing” is taking place in the project itself rather than in the mouse controllers or something like that. The shoot input action is left click. Upon pressing left click I am getting the intial location of the mouse, once I release left click I get the current location of the mouse and subtract that by the intial location. I then multiply that by -1.0 to get the inverse of it. I then apply linear physics to my projectile

The second screenshot shows my “Launch Velocity” function and to be honest I arrived at the function using trial and error so I can’t entirely explain it to you. This partially works, depending on where you drag to you may fly in the correct direction you may not. Either way it’s better to have something here for those who are searching for answers