VectorForce Force Is Massively Inflated

Hello,

I was attempting to create a simple gun (actually a cannon as it stands right now), but I ran into two problems regarding the VectorForce.

  1. When using the VectorForce and assigning it a Force vector, I find that the assigned vector’s magnitude and the actual VectorForce.Force’s magnitude end up being vastly different. I have something like this:
local bullet_spawn_vector_pos = script.Parent.BulletSpawn.Position
local back_vector_pos = script.Parent.BackPositionHolder.Position
local back_to_front_vector = Vector3.new(bullet_spawn_vector_pos.X-back_vector_pos.X,0,bullet_spawn_vector_pos.Z-back_vector_pos.Z) -- give vector only in XZ plane
-- Below excludes Y as it is 0 anyways
local magnitude = math.sqrt((back_to_front_vector.X)^2+(back_to_front_vector.Z)^2)
local unit_vector = Vector3.new(back_to_front_vector.X/magnitude,0,back_to_front_vector.Z/magnitude)
local force_vector = Vector3.new(unit_vector.X*script.Parent:GetAttribute("Force"),0,unit_vector.Z*script.Parent:GetAttribute("Force"))
local force = Instance.new("VectorForce")
-- Sorry it is so long
-- I am showing this in case it the VectorForce's configuration is messed up by me somehow
force.ApplyAtCenterOfMass = true
force.RelativeTo = Enum.ActuatorRelativeTo.World
force.Force = force_vector
force.Attachment0 = attachment0 --attachment0 is an attachment i created elsewhere in the code

Later on when I calculate and print the magnitudes of the force.Force and the force_vector the are vastly different.


The numbers are in pairs the first of which is the force_vector’s magnitude and the second is force.Force magnitude. Why is the magnitude so different even though they should be the same?

  1. Why does the projectile fling itself off of another object when it collides? Why doesn’t it just fall or something normal?

How can I fix this, or can I not?

Can’t answer the other questions, but I think it’s because it’s applying a constant force to the bullet. It doesn’t just apply it when it is first spawned. This causes the weird behavior when it collides with another part. If you want it to function like an actual gun, you should probably just use BasePart:ApplyImpulse.

2 Likes

Thank you so much. Switching to BasePart:ApplyImpulse() eliminates the other problem as VectorForce isn’t used anymore and can’t cause problems, though it would be nice to know why this happens for future reference.

Just reading this now, but if you still want to know why this is, it’s generally just basic physics.

Say if you fire a bullet from a gun in real life, there is only an initial force applied to that bullet during the flight, which is the explosion from the powder charge behind the bullet. This initial force accelerates the bullet to high speeds, but while airborne, other forces such as air resistance will try to counter the speed the bullet got from the gunpowder explosion, decelerating the bullet. When the bullet hits something, it likely still has some speed so the kinetic energy of the bullet is converted and the bullet reshapes and drops down.

On the contrary, if the bullet was constantly being propelled by a force the entire time, the bullet would actually pass through anything or push it forwards, since the force that is applied will keep accelerating the bullet. In roblox objects don’t pass through or reshape due to kinetic enegy upon impact, so the bullet will try to move around the object.