Create a basic ball function

I am pretty new to unreal. That said I have watched the tutorials and have search both here and on the web for an example of how to apply an impulse force to an object. Basically I want a ball that uses the basics physics model for interactive with the walls and ground but when a player hits it I want to apply an impulse like it was kicked. Here is the class blueprint I have tried

d659f1906c3e07ccdc2fa862eaa4d31b07be67cf.jpeg

Hey Anzak,

your image is way too small to take a look at your blueprint.
I experimented with ball physics as well, you can try to add a physic based ball with an impulse force. you can subtract your actor location from the player location to get a vector to get a direction for your impulse.

I’m currently with my girlfriend, if I get home by tomorrow I might upload my blueprint as an example. :slight_smile:

4.1 will have a physics rolling ball template that should help!

I hope I understood you correctly, that you have players who are able to shoot a ball.

That is a blueprint within a physic-based Sphere.
I add a Radial Impulse to the ball, from the location of the player within a certain radius of the player.
By increasing the Z-Value I can change the height of the Impulse and let the ball fly higher.
It’s quite simple and basic.

Quick question: why using the location of the player and not the location of the ball?

The target of course is the Ball, the origin of the force is the location of the player. So depending on which side of the ball you are before shooting the ball will go in the other direction. So you are always shooting forward.

Ok, understood. Thanks a lot for the explanation!

LAn,
Thank you for the example. Sadly I have been out of town the past few days and I will be heading back out in the morning. I will not get to play with this until next week. However I looked at the blueprint and while I have not completely studied mine against this to see where I would need to make changes I think I understand some of what I was doing wrong. You also solved another issue I was thinking about but had not really looked at how I would do it and that is making the player the center of the input.

JamesG,
I am looking forward to 4.1 and pulling the rolling ball apart.

LAn,
I finally got a chance to look at this. Was that a level blue print? I don’t see any option for AddRadialImpluse when I try to use a local class blue print on the ball. The closest I can see if AddRadialForceComponent and that works differently.

EventHit -> AddRadialForceComponent
GetPlayerCharacter -> GetActorLocation -> Vector + (100 on Z) -> MakeTransform (Location Pin) - AddRadialForceComponent (RelativeTransform Pin)

Since my images are not showing up correctly.

Oh and if it makes a difference the ball is a static mesh with a texture applied. It is a simple sphere I added a texture to and saved. I did enable physics on it as well. Currently when the actor hits the ball it moves out of the way since it is movable. It also has a small bounce when it hits the wall. So I am pretty sure that is enabled correctly.

Oh I finally got it. I was trying to use the AddRadialImpluse from the wrong place. I had to first do a Get on the ball and then use the pin from the ball to get the option for the AddRadialImpluse. Now it is time to play with the values a bit. It is doing basically what I want now.

Glad you got it working! You can’t add a force to an Actor (like your entire BP), because it could contain many different components, it doesn’t know which one to apply to! So you call it on a specific component (like your ball component).

I did play around with a few things last night. I have two questions. I tried added a random impulse from 0-10 on each axis and it does apply the impulse however it still seems the direction of the actor dictates the dominate direction of the ball. Secondly I tried to apply torque that seemed the logical choice but it does not seem to have any effect. I want to be able to apply a spin the the ball so it will act like it has English if you are thinking in terms of billiards. While the second it less important it would be a nice effect to have in my set of tools I am working with.

So if you want to aim where you kick the ball independent of location but dependent on where you are pointing and clicking (the camera being rotated freely despite character direction controlled by WASD) then you’d use the mouse click vector for direction of the force instead of the relative position of the character in possession of the ball. I had the idea of holding the mouse down for a while determines the power and then after clicking but still whilst holding down if you drag the mouse you can add some sort of spin. Then if you have the magnus effect the ball curves and you’ve got good control of the kick even though you just use the mouse.