Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
12/5/10 - Explosions, weapons, and more!
#1
Today's update is a big one, if you just want to play with some of the new stuff try this.
  • You can hold tools now. Set the Holdable property to true, then adjust the Texture, TextureOffset and Size to your liking.
  • Explosions! See below for an example
  • Fixed some random bugs
  • Players have health now, if you health reaches 0, you die. Explosions affect your health depending on how close to them you are.

Here is the code for the rocket:

Code:
tool = script.Parent
player = tool.Parent.Parent
character = player.Character
body = character.Body

enabled = true

function enable()
    enabled = true
    tool.Name = "Rocket"
end

function disable()
    enabled = false
    tool.Name = "Reloading..."
end

function playSound(s)
    if game.AssetService:getChild(s) ~= nil and game.AssetService[s]:isA("Sound") then
        game.AssetService[s]:play()
    end
end

function normalizeVector(vec)
    local m = math.sqrt(vec.x * vec.x + vec.y * vec.y)
    return Vec2D(vec.x / m, vec.y / m)
end

function onClick(btn, pos)
if btn == 1 then
    if not enabled then return end
    disable()
    local r = create("Box")
    r.Size = Vec2D(2, 1)
    r.Name="Rocket"
    local v = normalizeVector(Vec2D(pos.x - body.Position.x + 0.1, pos.y - body.Position.y - 1.5))
    local angle = math.atan2(v.y, v.x)
    
    local c = create("FixedVelocity")
    c.Velocity = Vec2D(v.x * 10, v.y * 10)
    c.Parent = r

    r.Rotation = math.deg(angle)
    r.Position = Vec2D(body.Position.x - 0.1 + v.x * 7, body.Position.y + 1.5 + v.y * 7)

    local s = create("Script")
    s.Name = "RocketScript"
    s.Source = [[
function playSound(s)
    if game.AssetService:getChild(s) ~= nil and game.AssetService[s]:isA("Sound") then
        game.AssetService[s]:play()
    end
end
rocket = script.Parent
function onCollide(hit)
    local e = create("Explosion")
    e.Radius = 7
    e.Position = rocket.Position
    e.Parent = game.World
    rocket:remove()
    playSound("Explode")
end
link(rocket.Collided, onCollide)
]]
    s.Parent = r
    r.Parent = game.World
    playSound("Rocket")
    sleep(4)
    enable()
end
end

link(script.Parent.MouseDown, onClick)

The part that creates the explosion is:
Quote: local e = create("Explosion")
e.Radius = 7
e.Force = 1000
e.Position = rocket.Position
e.Parent = game.World

The radius is how many units from the center the explosion force will travel; the force is how hard it will push on nearby parts. Explosions remove themselves automatically.
Reply


Messages In This Thread
12/5/10 - Explosions, weapons, and more! - by Jacob__mybb_import1 - 12-05-2010, 08:38 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)