![]() |
I'm trying to make a gun.... - Printable Version +- 2DWorlds Forums (http://2dworlds.buildism.net/forum) +-- Forum: 2DWorlds (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=4) +--- Forum: Scripting (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=13) +--- Thread: I'm trying to make a gun.... (/showthread.php?tid=1249) |
I'm trying to make a gun.... - sckum555 - 02-02-2011 Code: function mouseDown() It doesn't work... It's my first time scripting in Buildism. Can anyone fix this for me? RE: I'm trying to make a gun.... - Jacob__mybb_import1 - 02-03-2011 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] |