Help with making ball dynamically react with moving parts

  1. What do you want to achieve?
    I’m aiming for a system similar to Rocket League, where the ball reacts differently depending on which component of the car it hits and how fast the car is moving.

  2. What is the issue?
    Even though I’ve created a system that works in a similar way, the ball occasionally behaves incorrectly, such as when I’m travelling forward and strike the ball with the side, the ball slides to the left in an unrealistic manner. What I’m looking for is a dynamic reaction, where if I’m travelling forwards and the ball hits the front at high speed, the ball will fly high in the air, but if I’m moving forward and hit the ball with the top of my car, the ball should have little to no effect.

  3. What solutions have you tried so far?
    I’ve read other posts that sort of discuss this topic such as https://devforum.roblox.com/t/how-to-handle-ball-physics-in-roblox/58040/2 however when I tried to implement them the ball moved in a completely different direction.

This is the code that I use at the moment:

local Velocity = (Vehicle.HitBox.Position - Hit.Position).Unit * (Vehicle.HitBox.Velocity.Magnitude * 1.5)

local BodyVelocity = Instance.new("BodyVelocity", Hit)
BodyVelocity.Velocity = Velocity
BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

game.Debris:AddItem(BodyVelocity, 0.3)

It might be beneficial for us to see what direction it is moving in rather then the intended direction, as I believe your .Unit may be backwards, causing the ball to move into the striker, and causing unintended movement. To fix this would simply mean putting a negative in front of your .Unit.

Also, this code will not accomplish what you seek with “dynamic reaction” as you stated. You will just need to use physics for that. If you want to ball to be lighter and easy to push around, perhaps so this code isn’t required, you can set custom material properties, and change it’s density.

In the actual code the .Unit is already negative, I just forgot to make it negative in the code I provided. Making it use physics won’t work as well, since I also want the hit to be exaggerated, since the cars don’t travel very fast. Also, since the ball has its NetworkOwner set to nil, even with a density of 0.01 it wont react to a car hitting it, instead it will stop the car.

You can set the balls network owner to the nearest client, and also multiply the velocity of the ball shortly after a hit. Do you think this would do?

The only problem with that is setting the network owner will cause the ball to “warp” or “teleport”

I think that’s as good as it’ll get with Roblox limitations.

Is it possible to replicate the way the ball reacts to a hit from a car using BodyVelocity?

If you want it to work properly, it would be akin to coding your own physics. If your down to do try it, then sure. Don’t know if it would fix the problems stated earlier with network replication and such though.

I’ve already made a hacky network replication system, I just need help with calculating the forces and direction of the BodyVelocity.

Let me know if you have a solution

Well good luck then. Not very well educated on… physics engines.

Thanks, I finally figured out how to make it work properly using this:

-(Vehicle.HitBox.Position - Hit.Position) + (Vehicle.HitBox.AssemblyLinearVelocity + Hit.AssemblyLinearVelocity)
2 Likes