Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is the best way to make this projectile be rotated the right direction?

When I create a projectile I position its CFrame to be at the tip of the staffs CFrame which I know is the problem because when I shoot the projectile, it goes in the direction of the mouse UnitRay and the tip is not always rotated in that direction. What would be the best way to fix this problem?

local tip = script.Parent.Tip
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

local cast = game:GetService("ReplicatedStorage"):WaitForChild("Cast")

cast.OnClientEvent:Connect(function()	
	local p = Instance.new("Part")
	p.Parent = workspace
	p.Anchored = false
	p.BrickColor = BrickColor.new("Really red")
	p.Size = Vector3.new(1,1,3)
	p.CanCollide = false
	p.CFrame = tip.CFrame
	
	game.Debris:AddItem(p, 5)
	
	local bv = Instance.new("BodyVelocity")
	bv.Parent = p
	bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	bv.Velocity = mouse.UnitRay.Direction * 100
end)

1 answer

If I understood correctly, you want the velocity to be in the right direction of the tip. You can probably use CFrame#lookVector.

bv.Velocity = p.CFrame.lookVector * 100

Wiki:

Vector3 CFrame.LookVector

The forward-direction component of the CFrame’s orientation.

5 comments

0

Yes but then that make the projectile always go in the direction the tip is facing and not were the mouse was pressed

0

Well then what's the problem with your current code?

0

I want the projectile to face the way the it is moving. When I use the UnitRay it goes in the right direction, but it is sometimes rotated sideways

0

Can't you do CFrame.LookVector = mouse.UnitRay.Direction ?

0

Try using some of the direction properties here https://developer.roblox.com/en-us/api-reference/datatype/CFrame and see which one works best for your situation.

This discussion is preserved as it was. New answers, comments, and votes are closed.