How to apply Vector force, with correct orientation and position

I’m working on a gun system, and when the player shoots it spewts out a empty shell. It works, but i modified it a little, and i cant figure out how to apply the force while keeping the correct orientation to the gun. Here is what i mean.

local bv = Instance.new("BodyVelocity", bullet)
bv.MaxForce = Vector3.new(0,0,100)
bv.Velocity = Vector3.new(0,0, framework.viewmodel.HumanoidRootPart.CFrame.LookVector)

I’ve tried to add force to it by doing

local bv = Instance.new("BodyVelocity", bullet)
bv.MaxForce = Vector3.new(0,0,100)
bv.Velocity = Vector3.new(0,0, framework.viewmodel.HumanoidRootPart.CFrame.LookVector * 7.5)

and

local bv = Instance.new("BodyVelocity", bullet)
bv.MaxForce = Vector3.new(0,0,100)
bv.Velocity = Vector3.new(0,0, framework.viewmodel.HumanoidRootPart.CFrame.LookVector) * 7.5

neither added any force to it.

Any help is super appreciated, Thanks in advance!!

CFrame.LookVector is a Vector3 value.

If you’re only applying an instantaneous force/velocity, I’d suggest setting the AssemblyLinearVelocity property, or using BasePart:ApplyImpulse(), might save you some headaches with bodymovers / mover contraints.

Using bv is fine for, but I just don’t know how to apply a force and use orientation and cframe

You should be able to just use CFrame.LookVector * NUMBER as the velocity, I suggest using attachments to be able to fine tune them without needing to hardcode rotations/offsets.

It works better, but it still messes up at certain angles.

Can you show a video of what you mean?

i can’t send one, but what ill try to explain it better. say i have 2 lines that intersect (a,b are the lines) each line (a, or b) has its own -subsection a(a), a(b) etc… if your looking at a(a) it works, if your lookin at a(b) it works, but if your looking at b(a), or b(b) it doesnt work. Its like it goes forward on b(a) and backwards on b(b), but it works for a(a), a(b).

Are you using attachments to position the CFrame?

what do you mean? characters)wjeghwv

i have a part, and im setting the bullets position to that part with a slight offset.

Can you show how you’ve implemented that?

im going to improvise...

bullet cframe = parttotpto cframe * vector3.new(0,0,-.25) *  a few rotations

I have no way of checking if that calculation is correct, I strongly suggest using an Attachment so you can move it around and not need to hardcode the values in.

1 Like

ok i just connected it to a part in the exact psoition for it to spawn in.

it still has the same bug though.

Thank you for all of your help, i really do appreciate you taking this time to help my dumb self. I finally figured it out based on your suggestions. Have a great rest of your week!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.