Hello,
I’m doing a tank game, and i was wondering how to fire a bullet from the turret.
I’ve found teh britzl sample which do that well ( https://github.com/britzl/publicexamples/tree/master/examples/rotate_and_move ).
But there is something i don’t understand in the code.
Two things are puzzling me.
-- OK: get current rotation of player
local rotation = go.get_rotation()
-- hmm… why do we need to apply rotation to the position ?
-- Is for creating a matrix of quaternion ?
local position = go.get_position() + vmath.rotate(rotation, vmath.vector3(10, 40, 0))
-- I don't understand the second parameter of vmath.rotate function.
-- the 1000 value is on y axis, so i don't see the point with adding coordinates.
-- if i lower 1000 value, the bullet doesn't go far.
local to = position + vmath.rotate(rotation, vmath.vector3(0, 1000, 0))
-- OK for the rest.
local bullet = factory.create("#bulletfactory", position, rotation)
go.animate(bullet, "position", go.PLAYBACK_ONCE_FORWARD, to, go.EASING_LINEAR, 0.75, 0, function()
go.delete(bullet)
end)
Thank you.