Add force to object where player is aiming?

Hi there. I’m brand new to UE4 and I’m trying to have it so my player can add a force to a ball where ever his body is facing and whenever he clicks. That’s the basics of what I’m trying to do, but I’m also curious of some details. Does it need to be a blueprint or can it just be a physics based object? How can I control the amount of force it gives to the object and if the force is forward, back, up, down, left and right from the direction the player is facing? This is a more complex question, but can anyone give a general idea of how would I get a system like this where all players on a network server can use addforce on the same object via input?

This is as far as I’ve gotten with it. I’ve googled it but couldn’t find anything reliable. Any info relating to this is appreciated. Thanks in advance.

I took the time to do a little tutorial regards your question here. I hope it helps. UE4 Tutorial: multiplayer soccer, adding force to actor - YouTube

Just to make sure I understand you correctly, what you are trying to achieve is similar to all players on a server kicking a soccer ball around, right? If you left click on an object it should move in the direction you are looking?

Wow! Thank you! I’m astonished by the amount of effort you’ve given to answer my question. You’ve helped me a lot. I’ve encountered a few issues and I’ve been going over your video for the past 2 hours or so to try and fix them but I just can’t seem to figure out what I’ve done wrong. I hate to even ask really because you’ve already helped me so much but if it isn’t too much trouble, maybe you could help me troubleshoot these problems I’m having. The first is that the linetrace is not going where I am aiming. It starts from where I am at that moment, but it points towards the ball but underneath it as well. So if I click non-stop and run in a circle around the ball, regardless of what direction I’m facing while clicking, it looks like there’s a ring of red lasers. Here’s a picture of it and the section handling the line trace in the blueprint:

The second issue is that the ball movement isn’t synced properly with 2 players.

There are the replication settings I have for the ball. When I have 2 players in the same instance, it seems as though each client is interpenetrating the physics differently.I’ll push it with 1 player’s body and it will go a different direction or be at a different speed on the other client. Any ideas on how I can fix these? I hope I’m not prying by asking for even more help that you’ve already given me. If you want to contact me with skype my username is bryan.milos. Thanks again :slight_smile:

Actually I messed around with it some more, and for the linetrace, it seems to focus on where the ball first starts rather than where it is at the moment.

If you left click once and execute a line trace it will not follow the object that it “hits”. So when you left click a second time and the object moves the first line trace does not move.

You’re only using a line trace to tell you when a left click “hits” an Actor, in other words if you left clicked on an Actor.

Yes, I understand that but the linetrace only seems to point at the single spot where the ball is when I start playing. It doesn’t point where I am aiming.

Is the ball the root component of it’s actor blueprint? Also if this is going to be a soccer game do you want to have to look at the ball? Or just be near it?

The ball is a sphere that I attached to the component. My guess is that’s where I went wrong with it. I would also like it for the player to just be near it. I was trying to develop this on unity but I ran into problems with networking so I decided to switch to unreal. On unity I just attached a trigger to the player controller and had it so a player could only shoot or pass if it was in the trigger.

Yeah make sure the ball is it’s own actor, and that the ball component is the root. If you want to have the player interact when near the ball you could put a sphere trigger at players feet, the on click get overlapping actors, the through a for each loop check it’s collision response or tag to make sure it is the ball and add force. I am heading out soon but when I get back will do a follow-up video with this alternative set up

Wow man thank you. I’ll be looking out for it. I subscribed to your channel. I really like your content. That scifi game you play with your friends sounds really interesting :smiley:

Hey Brylos

Here is the follow up video: UE4 Tutorial: multiplayer soccer. Alternative force direction - YouTube

I have had fun with this question so please let me know if you need anything else. As for the “scifi I play with my friends” I am not sure which one you are referencing, that describes a few lol.

It’s beautiful :smiley: Thanks a ton man! I really appreciate the effort you put into helping me. I was also talking about your D20 arc series. I’ll be watching the new videos of it :slight_smile:

Hey Im new and I was watching your video and trying to get the same ball kick like you but in the new version of “* Float” i do not find anything… maybe the name changed but I cant set a float… so now im trying to find a way out… Can you help me please to get a new Version of the alternative video? I would appreciate it very much!

If we can connect in discord just tell me :slight_smile:

Hey @LOCOBRAAA! First off, welcome to the forums! Since this engagement was back in 2016, I’m not sure if they’ll ever see this. However, if you were to make your own post here on the forums with more information about your project and a question like this we can probably help out! I’d definitely need more information on where you’re stuck and to take a look at the blueprints as well. Let me know if you have any questions, and if you do end up making a full post, you can tag me in it and I’ll slide in and help there!