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

How do I rotate this projectile?

Asked by 6 years ago
Edited 6 years ago

My script is as follows...

01-- Set Function
02 
03local Rocket = Instance.new('Part') do
04    -- Set up the rocket part
05    Rocket.Name = 'Rocket'
06    Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
07    Rocket.Size = ROCKET_PART_SIZE
08    Rocket.Orientation = CFrame.Angles.new(0,0,math.rad(180))
09 
10Rocket.CanCollide = false
11 
12    -- Add the mesh
13    local mesh = Instance.new('SpecialMesh', Rocket)
14    mesh.MeshId = MISSILE_MESH_ID
15    mesh.Scale = MISSILE_MESH_SCALE
16 
17    -- Add a force to counteract gravity
18    local bodyForce = Instance.new('BodyForce', Rocket)
19    bodyForce.Name = 'Antigravity'
20    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

1Rocket.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:

01-- Create a clone of Rocket and set its color
02    local rocketClone = Rocket:Clone()
03    --game.Debris:AddItem(rocketClone, 30)
04    rocketClone.BrickColor = player.TeamColor
05    rocketClone.Touched:connect(function(hit)
06        if hit and hit.Parent and hit.Parent ~= player.Character and hit.Parent ~= tool then
07            rocketClone:Destroy()
08        end
09    end)
10 
11    spawn(function()
12        wait(30)
13        if rocketClone then rocketClone:Destroy() end
14    end)       
15 
View all 31 lines...
0
You should use CFrame to set the parts position and rotation User#5423 17 — 6y
0
How would I go about doing that? ExHydraboy 30 — 6y
0
as orientation takes into account collisions theking48989987 2147 — 6y
0
Cframe.Angles theking48989987 2147 — 6y
View all comments (13 more)
0
I have looked at this article. What would I put here --> "CFrame rotation = CFrame.new(--->) ExHydraboy 30 — 6y
0
Maybe (Rocket.x,Rocket.y*180,Rocket.z) ExHydraboy 30 — 6y
0
Change the position. Penomecco 9 — 6y
0
keep in mind that CFrame.Angles and the fromeuleangles functions all use radians , not degrees theking48989987 2147 — 6y
0
Hmm ok ExHydraboy 30 — 6y
0
How do I set radians? Sorry ExHydraboy 30 — 6y
0
CFrame.Angles(math.rad(),0,0) use math.rad(90) for rotation in radians greatneil80 2647 — 6y
0
CFrame.Angles(math.rad(),0,0) use math.rad(90) for rotation in radians greatneil80 2647 — 6y
0
Cool Thanks for the help... I'll reply after I attempt to rotate the mesh ExHydraboy 30 — 6y
0
@ExHydraboy can you also edit your question to include the attempt. User#5423 17 — 6y
0
Definitely ExHydraboy 30 — 6y
0
Updated ExHydraboy 30 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

1local Rocket = Instance.new('Part')
2 
3Rocket.Name = 'Rocket'
4Rocket.FormFactor = Enum.FormFactor.Custom
5Rocket.Size = ROCKET_PART_SIZE
6Rocket.CFrame = RocketLauncher.CFrame
7Rocket.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.

1local Rocket = Instance.new('Part')
2 
3Rocket.Name = 'Rocket'
4Rocket.FormFactor = Enum.FormFactor.Custom
5Rocket.Size = ROCKET_PART_SIZE
6Rocket.CFrame = RocketLauncher.CFrame * CFrame.new(0, 0, 5) -- move foward 5 studs check CFrame math operators
7Rocket.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.

1local Rocket = Instance.new('Part')
2 
3Rocket.Name = 'Rocket'
4Rocket.FormFactor = Enum.FormFactor.Custom
5Rocket.Size = ROCKET_PART_SIZE
6Rocket.CFrame = RocketLauncher.CFrame
7     * CFrame.new(0, 0, 5) -- position offset
8     * CFrame.Angles(0, 0, math.rad(180)) -- new rotation
9Rocket.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.

0
Thank You so Much! ExHydraboy 30 — 6y
0
I guess I should look a bit more into how to use CFrames LOL ExHydraboy 30 — 6y
0
no problem. CFrame logic can be a bit difficult to understand at first but check the wiki page and look up global and object space. User#5423 17 — 6y
0
I found a problem with the script I am editing... The CFrames for the Rocket are located BELOW the instance function ExHydraboy 30 — 6y
View all comments (2 more)
0
It's a clone function BUUUt I may have figured it out ExHydraboy 30 — 6y
0
At this stage I would make another question explaining the new problem and include screenshots. User#5423 17 — 6y
Ad

Answer this question