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 5 years ago
Edited 5 years ago

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
0
You should use CFrame to set the parts position and rotation User#5423 17 — 5y
0
How would I go about doing that? ExHydraboy 30 — 5y
0
as orientation takes into account collisions theking48989987 2147 — 5y
0
Cframe.Angles theking48989987 2147 — 5y
View all comments (13 more)
0
I have looked at this article. What would I put here --> "CFrame rotation = CFrame.new(--->) ExHydraboy 30 — 5y
0
Maybe (Rocket.x,Rocket.y*180,Rocket.z) ExHydraboy 30 — 5y
0
Change the position. Penomecco 9 — 5y
0
keep in mind that CFrame.Angles and the fromeuleangles functions all use radians , not degrees theking48989987 2147 — 5y
0
Hmm ok ExHydraboy 30 — 5y
0
How do I set radians? Sorry ExHydraboy 30 — 5y
0
CFrame.Angles(math.rad(),0,0) use math.rad(90) for rotation in radians greatneil80 2647 — 5y
0
CFrame.Angles(math.rad(),0,0) use math.rad(90) for rotation in radians greatneil80 2647 — 5y
0
Cool Thanks for the help... I'll reply after I attempt to rotate the mesh ExHydraboy 30 — 5y
0
@ExHydraboy can you also edit your question to include the attempt. User#5423 17 — 5y
0
Definitely ExHydraboy 30 — 5y
0
Updated ExHydraboy 30 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 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.

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.

0
Thank You so Much! ExHydraboy 30 — 5y
0
I guess I should look a bit more into how to use CFrames LOL ExHydraboy 30 — 5y
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 — 5y
0
I found a problem with the script I am editing... The CFrames for the Rocket are located BELOW the instance function ExHydraboy 30 — 5y
View all comments (2 more)
0
It's a clone function BUUUt I may have figured it out ExHydraboy 30 — 5y
0
At this stage I would make another question explaining the new problem and include screenshots. User#5423 17 — 5y
Ad

Answer this question