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
task.wait()
Force:Destroy()
end
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
I’ve tried that, but that just sends the gun casing flying, I’m guessing that could be because of the difference in mass between the player and the casing.
I made a mistake you’re supposed to do .Unit not .Magnitude, but you probably ignored anyways it since it would otherwise throw an error
It should actually be weaker than the original velocity you have since (1, 1, 0) has a length of sqrt(2) while a normalized vector always has a length of 1
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
Casing:ApplyImpulse(Force)