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.
- 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?
- 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?