Spaceship rotation (SOLVED)

Hi all,

i have this script from tutorial. all works fine. but now i want to rotate the spaceship und oly in the direction he looks up i want to speed up not backwards … actually the movement works fine but right,left,down,up all the same

how can i do this?

    go.property("max_speed", 800)
go.property("acceleration", 800)

local ACCELERATE = hash("ACCELERATE")

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("camera", "acquire_camera_focus")
	self.velocity = vmath.vector3()             -- [1]
	self.input = vmath.vector3()
end

function update(self, dt)
	if vmath.length_sqr(self.input) > 1 then
		self.input = vmath.normalize(self.input)
	end

	local acceleration = self.input * 200       -- [2]

	local dv = acceleration * dt                -- [3]
	local v0 = self.velocity                    -- [4]
	local v1 = self.velocity + dv               -- [5]
	local movement = (v0 + v1) * dt * 0.5       -- [6]

	local p = go.get_position()
	go.set_position(p + movement)               -- [7]

	self.velocity = v1                          -- [8]
	self.input = vmath.vector3()
	
end

function on_message(self, message_id, message, sender)
	-- Add message-handling code here
	-- Remove this function if not needed
end

function on_input(self, action_id, action)
	if action_id == hash("up") then
		self.input.y = 1                     -- [1]
	elseif action_id == hash("down") then
		self.input.y = -1                    -- [1]
	elseif action_id == hash("left") then
		self.input.x = -1                    -- [1]
	elseif action_id == hash("right") then
		self.input.x = 1                     -- [1]
	elseif action_id == hash("click") and action.pressed then
		print("CLICK!")
	end
end

function on_reload(self)
	-- Add reload-handling code here
	-- Remove this function if not needed
end

Please try and proof-read what you write before posting. I do recognise that not everyone on the forum is a native English speaker, but with formatting, punctuation and basic spell checking it makes it easier for everyone to understand what you mean and give you help.

So you want to rotate the game object? And you don’t want to be able to move backwards?

Did you see my example: publicexamples/examples/rotate_and_move at master · britzl/publicexamples · GitHub

1 Like

Sry for my English
Yes i want to rotate it. i see your examples but iam so nooby i dont know how to use it … i dont know whats important for me …

I’ve isolated it down to an even simpler example:

CODE: https://github.com/britzl/publicexamples/tree/master/examples/top_down_spaceship
DEMO: http://britzl.github.io/publicexamples/top_down_spaceship/index.html

4 Likes

thank you very much this example is much better to understand for me :slight_smile: and now all fine … thank you so much :slight_smile:

1 Like