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

How would I rotate a projectile to face the direction it's going?

My current script: (that fires the part)

local spellPart = game.ReplicatedStorage.Spells.Ignis.IgnisSpell:Clone()
spellPart.Parent = game.Workspace
spellPart.CFrame = tip.CFrame

local bv = Instance.new("BodyVelocity")
bv.Parent = spellPart
bv.velocity = ((mousehit - spellPart.Position).unit) * 150

(More code above that, but those arent essential to this.)

I have inside the "spellPart" a particle emitter, which is basically telling me that it's not rotating properly. The particle emitter is back emitting, so if it were to be firing straight, the emitter would be a trail, but its inconsistent. Sometimes its a trail, sometimes it's not, basically, the part isn't rotating.

How would I go about changing the orientation/rotation to the straight direction the part is traveling?

1 answer

✓ Accepted answer

Since you are giving spellPart a BodyVelocity I will assume that it is unanchored.

To keep the spellPart's orientation, you can use a BodyGyro and the second parameter of CFrame.new()

local spellPart = game.ReplicatedStorage.Spells.Ignis.IgnisSpell:Clone()
spellPart.Parent = game.Workspace
spellPart.CFrame = tip.CFrame

local bv = Instance.new("BodyVelocity")
bv.velocity = ((mousehit - spellPart.Position).unit) * 150
bv.Parent = spellPart


local bg=Instance.new("BodyGyro")
--set the direction to change where the spellPart points to
--destination must be a vector3
bg.CFrame=CFrame.new(spellPart.Position,destination)
bg.MaxTorque=Vector3.new(400000,400000,400000)
bg.Parent=spellPart

1 comment

0

Thanks a lot for your help!

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