My script is as follows...
-- Set Function local Rocket = Instance.new('Part') do -- Set up the rocket part Rocket.Name = 'Rocket' Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size Rocket.Size = ROCKET_PART_SIZE Rocket.Orientation = CFrame.Angles.new(0,0,math.rad(180)) Rocket.CanCollide = false -- Add the mesh local mesh = Instance.new('SpecialMesh', Rocket) mesh.MeshId = MISSILE_MESH_ID mesh.Scale = MISSILE_MESH_SCALE -- Add a force to counteract gravity local bodyForce = Instance.new('BodyForce', Rocket) bodyForce.Name = 'Antigravity' bodyForce.force = Vector3.new(0, Rocket:GetMass() * GRAVITY_ACCELERATION, 0)
When the script is executed the projectile is fired backwards out of the Rocket Launcher. I know that in order to determine the Rotation I put
Rocket.Orientation = Vector3.new(???,??? * ???, ???) -- This is where I encounter problems.
Thanks for your consideration!
The Bottom Line: How to call rotation functions and how to determine rotation using Vector3.
Thanks
EDIT
Ok SO basically I have added the CFrame to the Projectile, but the mesh itself will not rotate. I cannot figure out how to change it
Here is the script:
-- Create a clone of Rocket and set its color local rocketClone = Rocket:Clone() --game.Debris:AddItem(rocketClone, 30) rocketClone.BrickColor = player.TeamColor rocketClone.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent ~= player.Character and hit.Parent ~= tool then rocketClone:Destroy() end end) spawn(function() wait(30) if rocketClone then rocketClone:Destroy() end end) -- Position the rocket clone and launch! local spawnPosition = (tool.Handle.CFrame * CFrame.new(2, 0, 0)).p rocketClone.CFrame = CFrame.new(spawnPosition, target)* CFrame.Angles(0 ,0 ,0) --NOTE: This must be done before assigning Parent rocketClone.Velocity = rocketClone.CFrame.lookVector * ROCKET_SPEED --NOTE: This should be done before assigning Parent rocketClone.Parent = game.Workspace -- Attach creator tags to the rocket early on local creatorTag = Instance.new('ObjectValue', rocketClone) creatorTag.Value = player creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats local iconTag = Instance.new('StringValue', creatorTag) iconTag.Value = tool.TextureId iconTag.Name = 'icon' delay(attackCooldown, function() canFire = true
In most cases you will just be setting the parts CFrame as this contains both the position and rotation. If you are using Orientation then it needs to be a Vector3 and not a CFrame.
For this task you should be using CFrame. As this is a rocket launcher the starting point of the rocket will be at the rocket launcher CFrame.
local Rocket = Instance.new('Part') Rocket.Name = 'Rocket' Rocket.FormFactor = Enum.FormFactor.Custom Rocket.Size = ROCKET_PART_SIZE Rocket.CFrame = RocketLauncher.CFrame Rocket.Parent = workspace
The next stage is to include an offset to position the pocket at the end of the RocketLauncher. For this we will add an offset in object space as the RocketLauncher is facing the direction that the rocket is shooting we just need to add onto this facing direction to get to the end of the RocketLauncher.
local Rocket = Instance.new('Part') Rocket.Name = 'Rocket' Rocket.FormFactor = Enum.FormFactor.Custom Rocket.Size = ROCKET_PART_SIZE Rocket.CFrame = RocketLauncher.CFrame * CFrame.new(0, 0, 5) -- move foward 5 studs check CFrame math operators Rocket.Parent = workspace
The last stage now that the Rocket is in the correct position is to include the correct roation. This is done by using CFrame.Angles with the correct rotation in radians.
local Rocket = Instance.new('Part') Rocket.Name = 'Rocket' Rocket.FormFactor = Enum.FormFactor.Custom Rocket.Size = ROCKET_PART_SIZE Rocket.CFrame = RocketLauncher.CFrame * CFrame.new(0, 0, 5) -- position offset * CFrame.Angles(0, 0, math.rad(180)) -- new rotation Rocket.Parent = workspace
You might need to do some testing to get the correct rotation.
I hope this helps. please comment if you have any other questions.