How to create CFrame with just position, no rotation

So the title pretty much sums it up. I’m trying to make a shooting mechanism and I shoot model towards a different player. The problem is that it rotates to the players humanoid root part orientation too. Here is the code

local model = script.Model:Clone()
						model:SetPrimaryPartCFrame(CFrame.new(player.Character.HumanoidRootPart.Position, closestPlayer.Character.HumanoidRootPart.Position))
						model.Parent = player.Character
						local CFrameValue = Instance.new("CFrameValue")
						CFrameValue.Value = model:GetPrimaryPartCFrame()

						CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
							model:SetPrimaryPartCFrame(CFrameValue.Value)
						end)
						local tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
						local CF = CFrame.new(closestPlayer.Character.HumanoidRootPart.Position)
						local tween = TweenService:Create(CFrameValue, tweeninfo, {Value = CF})
						tween:Play()
						tween.Completed:Connect(function()
							CFrameValue:Destroy()
						end)

Does anyone know what’s going on here? I searched it up and by just giving a Vector3 it shouldn’t give it any rotation.

1 Like

Maybe this line

model:SetPrimaryPartCFrame(CFrameValue.Value)

Change it to

model:SetPrimaryPartCFrame(CFrame.new(CFrameValue.Value,model.PrimaryPart.CFrame))

and maybe that could work?

I’m not sure if you can do CFrameValue.Value.p to get the position of a CFrame value. You could try to put the value in a variable and do that as .p

That line isn’t the problem. That’s just because I’m tweening the model. This line tells the tween where to tween the model too

local CF = CFrame.new(closestPlayer.Character.HumanoidRootPart.Position)

Maybe change it to?

local CF = CFrame.new(closestPlayer.Character.HumanoidRootPart.Position,model.PrimaryPart.CFrame)

Why exactly do you need to use CFrames in this case anyways?

I tried it and it’s not tweening at all now

That’s odd, but again, if I may ask, why do you need to use CFrame? CFrames typically hold a Position and a Rotation again, if you’re doing that to move the model, can’t you just do this?

CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
	local cframe = CFrameValue.Value
	model:MoveTo(cframe.p)
end)

So it moves the model with the Position of the CFrame only?

This kind of works but I get this up and down motion with the tween


It looks like as if can collide is on for the parts but it’s not. I’ve set can collide to off

EDIT: After some reading I found this for the :MoveTo function

If there are any obstructions where the model is to be moved to, such as Terrain or other BasePart s, then the model will be moved up in the Y direction until there is nothing in the way. If this behavior is not desired, Model:SetPrimaryPartCFrame should be used instead.

Wait, can’t you just tween the model itself? You can weld the stuff together and just tween the primary part.

Here’s a guide to tweening a model to help you do it simpler

I’ve tried that but only the primary part moves. The rest of the model doesn’t move

I think you may’ve messed up a step. Maybe you could union the part so it’s a single thing and just tween that?

I haven’t, I have unanchored all the parts except for the root part and I have welded them together. Also I can’t make a union as they are mesh parts

Hmm…How much did it rotate? Was it a noticeable rotation?

This is what happens. The primary part moves but the other one doesn’t

No no when you were still using the very first script you showed in your post, how noticeable was the rotation?

It depends on the position the other player stands in but it is pretty noticeable

Okay wait I think I know what it coudl be, keep the Event to this

CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
	model:SetPrimaryPartCFrame(CFrameValue.Value)
end)

But change here

local CF = CFrame.new(closestPlayer.Character.HumanoidRootPart.Position)

To this?

local pos = closestPlayer.Character.HumanoidRootPart.Position
local CF = CFrame.lookAt(pos,pos)

So it sets the CFrame to where the rootpart is and makes it look at the rootpart?

I’ve tried that but it doesn’t work. For some reason it sets the position to (0, -1000000, 0)

I think I’ve figured something out. I just took the CFrame and flipped it by 180 degrees. This is what the line looks like

local CF = CFrame.new(closestPlayer.Character.HumanoidRootPart.Position, player.Character.HumanoidRootPart.Position) * CFrame.Angles(0, math.rad(180), 0)

That would maybe work since it’s setting the position and the lookAt to the closest player and then flipping it, try it out and see how it goes?

First off, remove that. You are ruining the purpose of a tween.

Second,

Let’s fix this.

local pos = closestPlayer.Character.HumanoidRootPart.Position
local pos2 = mainplayerhere.Character.HumanoidRootPart.Position

local CF = CFrame.lookAt(pos2,pos) -- Pos2 being the "from", pos being the "to".

This would create a thing where it would be pointing at the player while it is going towards them, and then when getting close it would turn sideways or like “flat”.

You could have just made it so the mouse can be going to the player from like 3 - 7 studs away, and when the mouse makes contact it makes a effect that it’s disappearing, and the player would die in-game too.