# CFrame Math to always obtain 10 studs behind a CFrame object, with respect to orientation and direction

Trying to set a CFrame of an object 10 studs behind another object using their CFrame, but so far none of the resources I looked help have helped as they seemingly dont respect the orientation/direction of the object wondering if someone can help out.

To Create an Offset, do this:

``````YourPart.CFrame = AnotherPart.CFrame + Vector3.new(0,0,-10)

``````

perhaps there is something wrong with my cframes as that was one of the equations i used and it always made the object towards the right of the cframe

To create an offset based on the current orientation would be

`ThePart.CFrame = ThePart.CFrame * CFrame.new(0, 0, -5)`

That causes an offset exactly 5 studs in front, based on the orientation where the part is facing

text

``````--obtaining origin and direction (used for cframe)
local Origin 		= WeaponInHand.Handle.Muzzle.WorldPosition
local Direction 	= WeaponInHand.Handle.Muzzle.WorldCFrame.LookVector + (WeaponInHand.Handle.Muzzle.WorldCFrame.UpVector * (((WeaponData.BulletDrop * WeaponData.CurrentZero/4)/WeaponData.MuzzleVelocity))/2)

local BulletCF 		= CFrame.new(Origin, Direction)

--for viewing i cloned a bullet to be visible and it seems to always spawn in one area of the world

local Cloning = Instance.new("Part",workspace)
Cloning.Name = plr.Name.."_Bullet"
Cloning.CanCollide = false
Cloning.Shape = Enum.PartType.Ball
Cloning.Transparency = 1
Cloning.Size = Vector3.new(1,1,1)

Cloning.Anchored=true
Cloning.Transparency=.5

Cloning.CFrame=BulletCF+ Vector3.new(0,0,-10)
Cloning.Parent=workspace

``````

me walking backwards while shooting

This is because (I think) you are creating a new CFrame, the script is trying to look for a Instances CFrame

if you mean for bulletcf no, i tested (seperately, not shown in sample code) with using the muzzle.worldcframe, and handle.cframe (not using cframe.new(origin, direction) and i get similar results

I believe it depends on the axis you are offsetting from…

Try changing the axis of the -10 to :
Cloning.CFrame=BulletCF+ Vector3.new(0,-10,0)
or
Cloning.CFrame=BulletCF+ Vector3.new(-10,0,0)
and if those don’t work then change the -10 to a positive 10

I really think that adding the offset with Vector3.new wont work correctly, cause its based on World Coordinates
Should be:

Try this:

``````		Cloning.CFrame= WeaponInHand.Handle.Muzzle.WorldCFrame  * BulletCF + Vector3.new(0,0,-10)
``````

Remive The BulletCF if it doesnt work idk

this is what happened when i shot in place at the spawn location and rotated 360 degrees

it spawns no where close for whatever reason

though it does follow the player, I may have to manually test and fine the offset value…

idk it just doesnt seem to be working tbh and i dont know why

solved by using lookvector

``ClonedBullet.CFrame = BulletCF+(-10*WeaponInHand.Handle.Muzzle.WorldCFrame.LookVector)``

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