Tweening CFrame rotates the part

I’ve got an issue when Tweening CFrames…

I’m making a pistol for a game, I’ve never tried something like that so I didn’t know which was the best way to make the bullets, I thought making a projectile using BodyVelocity but I ended up using TweenService.
I made sure that the bullet faces towards the players mouse, but when Tweening the bullets position to it, it also rotates, like this:

I’ve tried alot of weird stuff, my closest attempt was tweening the cframe using “CFrame.lookAt” but it still did not work. I’ve also tried to tween the Position instead of the CFrame but it also didn’t work for some reason

I dunno if it’s necessary but heres the tweening code:

TS:Create(Bullet, TweenInfo.new(Bullet_Time), {CFrame = CFrame.new(Mouse_Pos)}):Play()

Sorry If it has a very simple solution and I don’t know it Im kinda new to scripting

When you are Applying a CFrame, You would be Effecting Both the Position and Orientation of the Object.

So you may need to realign the Bullet to the correct rotation using CFrame.Angles / CFrame.fromEulerAnglesXYZ

I see, but can I tween the Position and realign the Angles in the same tween? Could you give me an example?

You can, You just Multiply the Position and Rotation like so:

Position = CFrame.new(0, 1, 0)
Rotation = CFrame.Angles(0,0,0) 

-- CFrame.Angles uses Radians to Apply a Rotation
-- 180 degrees in radians is math.pi
-- 360 is math.pi*2
-- 90 is math.pi/2

-- Multiply them like so
Goal = {CFrame = Position * Rotation} -- Should work


1 Like

Just obtain the initial rotation of the bullet and supply that to the tween parameters, currently with no rotation supplied it ends up tweening to (0,0,0):

TS:Create(Bullet, TweenInfo.new(Bullet_Time), {CFrame = CFrame.new(Mouse_Pos,Bullet.CFrame.LookVector)}):Play()
1 Like

Doing it like that gives me this error (The mouses position is a Vector3 and not a CFrame?)

image

I can’t quite get this to work, It changes how the Bullet lands but it’s still not facing forwards where the LookVector would be

I have found the solution myself, I wanna say thanks to everyone who helped me but yeah…
My solution is probably not ideal, but It’s what made it work after all.

All I did was make an invisible part on the Mouse’s Position, make it look at the gun’s handle, rotate it 180 degrees and tween the bullet to It’s CFrame

local Destination = Instance.new("Part")
		Destination.Name = "BulletDestination"
		Destination.Anchored = true
		Destination.Parent = workspace
		Destination.Transparency = 1
		Destination.Size = Vector3.new(1, 1, 1)
		Destination.CanCollide = false
		Destination.CanTouch = false
		Destination.CFrame = CFrame.lookAt(Mouse_Pos, Gun.Handle.Position)
		Destination.CFrame = Destination.CFrame * CFrame.Angles(0, math.pi, 0)
		task.delay(3.2, function()
			Destination:Destroy()
		end)
		
		TS:Create(Bullet, TweenInfo.new(Bullet_Time), {CFrame = (Destination.CFrame)}):Play()

So yeah…

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