I'm trying to make a gun....
#1
Code:
function mouseDown()
    local bullet = create("Cirle")
    c.Radius = 2
    c.Position = script.Parent.Handle.Position
    c.Name = "Bullet"
    c.Parent = game.World
    local rocket = create("Rocket")
    rocket.Parent = bullet
end

link(script.Parent.MouseDown, mouseDown)

It doesn't work... It's my first time scripting in Buildism. Can anyone fix this for me?
Reply
#2
There's currently no way to get the position of the tool. Until that is added, the only way to do it is to turn the tool's rotation into a vector, multiply it by the length and add it to the character's position.

Example from the rocket tool:

[lua]
function normalizeVector(vec)
local m = math.sqrt(vec.x * vec.x + vec.y * vec.y)
return Vec2D(vec.x / m, vec.y / m)
end
[..]
body = character.Body
local v = normalizeVector(Vec2D(mousepos.x - body.Position.x + 0.1, mousepos.y - body.Position.y - 1.5))
bullet.Position = Vec2D(body.Position.x - 0.1 + v.x * 7, body.Position.y + 1.5 + v.y * 7)
[/lua]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)