How to give actor components velocity?

I have a game mechanic which I thought would be straight forward to implement but turns out to be the opposite.

Basically; I am trying to make a retro top down soccer game in style of Sensi Soccer. I’ve got rudimentary control, drag, and curveball systems working but I’m stuck on my semi “sticky ball” mechanic.

When the player is in possession of the ball he nudges it forward. The drag system will slow it down enough for him to catch up to it again enabling to once again nudge it forward while running. This part works fine. It’s when the player changes direction that it breaks down. I can’t get the ball to stay on the same path as the players’ direction.

Basically I need the ball to stay directly in front of the player while keeping its’ own momentum.
I want this to be physics based rather than just attaching the ball to a spring arm as I have plans to do more with this system in the future.

I’ve been told that I should do this in local space. This is how they recommended I should do it:

1. Track the relative position:
When the player is moving with the ball, calculate where the ball should be in local space—maybe something like 50 units in front and a few to the side of the player's feet, depending on how it looks best.

2. Store that offset as a vector:
Keep it in a variable so you know where the "ideal dribble spot" is.

3. Don’t fight physics—use components smartly:
Instead of constantly applying forces to keep the ball in place (which is fragile), you could have a second version of the ball as a component on the player that only activates when the player is in dribble mode. This version visually follows that relative position and moves at the player's speed (plus a bit of inertia/drag to sell the weight).

4. Use distance and conditions to switch modes:
If the ball is too far from the player, or they turn too fast, then drop out of “dribble mode.” Destroy the component and spawn the physics ball again with a force that mimics the kick.

5. From there, you’re free to tinker:
Add slowdown curves, mini-kick nudges, or predictive paths based on movement speed. The trick is to make it feel good, not to make it physically accurate.

It sounds complicated, but it’s really just three parts:

A "visual trick" ball while dribbling (as a component)

A system to decide when you're in or out of dribble mode

And a way to re-spawn the real ball when control is lost
type or paste code here

It’s the third point that I don’t understand. How can I give the ball inertia and drag while in local space?

This is a case of it can be implemented simple, or ultra complex, but mostly your choice.
Sensible soccer is a realistic type? I mean compared to a Bomberman 3D where physics and graphics are basically non existent but just enough to make the gameplay work. From your description, I sense your project inspired by sensi socker is on the realistic side.

realism == complexity. You say you don’t understand the third point of the advice given (the rest is no problem). However, I want to go over the points for a bit so we can build an image together of the final product.

3.:
There are two ways to handling dribbling, a character with a ball.

  1. accurate physics (trust me, this is not going to be possible to implement)
  2. “attaching” the ball to the character, so that if the character moves, the ball moves 1:1 relative to the character.

The latter is the way to go. Accurate physics would have you match ball movement to character (animation, turning around etc.), environment physics (grass, obstacles) and such which are both complex to developer and impossible to control with a keyboard or joystick by player.

Here’s 1 of several smarter approaches:

-3. You can create a socket or bone on the skeletal mesh of a character called “ball_position”. This would be a bone attached to the pelvis (root bone). This can be either animated or used as a reference point for IK. A ball (as component, or as actor) can be attached to this socket, to its transform. The idea there is to integrate ball movement with character animation, without the need for any complex (fragile) calculations. For example, if the character turns around 180 degrees, the ball will always follow. Any dynamics in ball behavior while dribbling can now be animated by hand on the character skeleton.

-4 if the player is too far from the ball, or they run too fast, de attach the ball and re enable physics until near enough to a player running below speed X.

-2 no longer required

-1 no longer required.

-5 integrated with 3.

You could even detect the speed or velocity of socket “ball_position” by comparing positions between frames, and say, if the player rotates 180 degrees to fast he loses the ball as well. However you implement such mechanics that in your example were various steps, you can centralize the management of that mostly to the animation system.

Thinking of something event based like:

Character animation blueprint:

  • If X happens during animation (state change like the player falls), broadcast “lose ball”.
  • If character velocity > X, broadcast “lose ball”

I’d say 99% of the events you take or lose a ball, depend on the state of animation anyhow, and are visual events, so you’d have the animation blueprint manage those events.

Definitions, references:

Sockets are commonly added within UE to add a point to attach stuff to, like a helmet on a head. They are also useful as reference points in IK (Inverse Kinematics). IK is used to automatically alter an animation to match a position, like hands on a rifle or feet on stairs.

Skeletal Mesh Sockets in Unreal Engine | Unreal Engine 5.5 Documentation | Epic Developer Community

The most flexible is adding a bone “ball position” attached to the skeleton root (pelvis) in specialized software like Blender, creating a ball transform animation with it during the skeletons dribble animation, then importing that into unreal.

Once in unreal, you attach the ball to the bone or socket and done. Bonus: you really don’t need to add a second “actor” or component to visualize the ball on the character. Just use the existing one as is.

How do I attach an actor to an actor? - #2 by anonymous_user_923c79df

If you have trouble with walking after attaching the ball actor to the character, note that you might have to play with collision so that the character (and actually, nothing else) is affected by collision of the ball. You can also alter collision of the ball temporarily. I did this a while back in c++, let me know when sh"t hits the fan then I will take a look.

Hey. Thank you for the detailed reply!
Man, I never imagined such a simple idea to be so complicated. It’s a little disheartening to be honest. It’s obvious that I need to learn so much more before continuing.

1 Like

Some say game dev is the most difficult type of software dev. A lot of ideas should be simplified as much as possible in the plan before starting the actual programming, but yea you do end up having to learn a lot of stuff to get things on screen. I have 10+ years experience in the field and I’d say if you love X you won’t regret X, but there’s a ton of obstacles you might not love :slight_smile: . Some people I discussed things with said that a lot of software and techniques seem to much to learn, they want a 1 to 100 tutorial and sometimes there is one, but often there’s just tons of documentation to puzzle together, because even if there is such tutorial, you still got to fly that airplane if there’s a little difference in planned situation. A bug or design change or a new version of the tools and you’ll still have to dig into the info online.

Sure! Here’s the direct answer:

To give actor components velocity (for example, in Unreal Engine), you typically need to apply movement through a physics simulation. Actor components like a StaticMeshComponent or PrimitiveComponent have built-in functions to set velocity if physics is enabled.

Here’s how you can do it:

Step-by-Step:

  1. Make sure physics simulation is enabled on the component:

    YourComponent->SetSimulatePhysics(true);
    
  2. Set the velocity directly:

    YourComponent->SetPhysicsLinearVelocity(FVector(1000, 0, 0));
    

    (This example gives it velocity in the X direction.)

Important:

  • If Simulate Physics is off, setting velocity won’t do anything.
  • You can also add forces or impulses for more natural movement:
    YourComponent->AddImpulse(FVector(1000, 0, 0));
    

Summary:
:backhand_index_pointing_right: Enable physics simulation ➔ then use SetPhysicsLinearVelocity or AddImpulse to give it velocity.

Would you like a quick example in Blueprints too? :video_game::rocket: