Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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
0
Thanks a lot for your help! ImperiumDomini2 39 — 4y
Ad

Answer this question