Guys im not the biggest Trigonometry fan but I’m trying to convert my platformer game from Java. How can I convert this to lua based code? It is a projectile that fires at the players last position when it was spawned.
I have not tested this code, but something like this:
function init(self)
self.velocity = go.get_position("/player") - go.get_position()
if vmath.length(self.velocity) > 0 then
self.velocity = vmath.normalize(self.velocity)
end
self.removetimer = 2 -- seconds!
end
local SPEED = 400 -- pixels per second
function update(self, dt)
-- update position
local new_position = go.get_position() + self.velocity * SPEED * dt
go.set_position(new_position)
-- timer
self.removetimer = self.removetimer - dt
if self.removetimer <= 0 then
go.delete()
end
end
Got it working thank you. Just a curious question about tile maps. Does the collision get simplified combining each tile as one collision object or does it remain as individual squares(etc) at run time specified in the tilesource?
I have a flying enemy that follows the player around and shoot the projectiles at him and I set a condition to not fire if its colliding(using collision_response) with the tiles. I notice it only works when the enemy is at the outer tiles but still fires when its deeper and the projectile get removed at the outer tiles as well
SCENARIO 1
Yep, there’s issues with tilemap collisions when entirely inside a tilemap. This was recently posted about by @andreas.strangequest and assigned a ticket.