I am trying to make a FPS framework, and I’m currently making a casing eject system. So far it works, but I wish that the casings would move not just in the direction given to it but also in the direction of player’s movement. I’m using VectorForce to give the casing velocity.
local function dropcasing(v)
local Casing = v.Casing.Value:Clone() -- the casing
local Velocity = v.Vel.Value -- velocity of the casing without the player's velocity being applied
Casing.CFrame = v.CFrame -- v is the part from which the casing is ejected
local Att = Instance.new("Attachment",Casing)
local Force = Instance.new("VectorForce",Casing)
Force.RelativeTo = "Attachment1"
Force.Attachment1 = v.Attachment
Force.Attachment0 = Att
Force.ApplyAtCenterOfMass = true
Force.Force = Velocity
So far, I’ve tried getting the player’s movement direction relative of the player’s HRP rotation, multiplying it by casing velocity, and adding it to casing velocity, like this
local Velocity = v.Vel.Value + v.Vel.Value * Character.HumanoidRootPart.CFrame:VectorToObjectSpace(Character.Humanoid.MoveDirection)
The velocity for the casing is (1,1,0), if that helps
Okay, I ended up fixing the issue. What I did was I took the player’s HRP’s velocity and multiplied it by the mass of the casing being ejected, to get the force I needed to apply to the casing to get the same velocity as the player (F = M*V/T).
local Velocity1 = Character.HumanoidRootPart.AssemblyLinearVelocity -- Player's HRP velocity
local Velocity2 = Vector3.new(8,15,0) -- Velocity that had to be applied to the empty casing
local Force = (Casing.CFrame:VectorToWorldSpace(Velocity2) + Velocity1) * Casing.Mass -- The force that has to be applied to the casing