Triangle movement

Hi all,

Iam new with defold but its a amazing engine i love it …

For my first Tests i play a little with a Triangle sprite and i want to move it like a “ship” who is the top of it always in the front … i have a basic movement script but i dont know how can i do this. lua is always new for me and i hope i get some help …

also i want to have a speed variable … local speed

    function init(self)
	msg.post(".", "acquire_input_focus") 
	self.vel = vmath.vector3()     
end

function update(self, dt)
	local pos = go.get_position() 
	pos = pos + self.vel * dt 
	go.set_position(pos) 

	self.vel.x = 0 
	self.vel.y = 0
end

function on_input(self, action_id, action)
	if action_id == hash("up") then
		self.vel.y = 150 
	elseif action_id == hash("down") then
		self.vel.y = -150
	elseif action_id == hash("left") then
		self.vel.x = -150 
	elseif action_id == hash("right") then
		self.vel.x = 150
	end
end

Thanks for help

1 Like

I have an example of how to rotate a sprite and move it in the direction it is facing: https://github.com/britzl/publicexamples/tree/master/examples/rotate_and_move

3 Likes

thanks britzl, lot of examples i try to understand it :wink: you are casually german?

3 Likes

No, born and bred in Sweden. :slight_smile:

1 Like