My movement isn't working and idk why

I’ve been following an online tutorial and I’m pretty sure I copied all the code correctly but the movement won’t work, and I don’t think the gravity or collisions do either.

pls help
tutorial I’ve been following: https://www.youtube.com/watch?v=V3iJtpvAOxU&t=579s

My code copy and pasted:

local DIRECTION_RIGHT = 1
local DIRECTION_LEFT = -1
local BASE_VELOCITY = 500
local GRAVITY = 1000

function init(self)
	msg.post("#", "acquire_input_focus")
	self.velocity = vmath.vector3(0, 0, 0)
	self.ground_contact = false
end

function walk(self)
	self.velocity.x = BASE_VELOCITY * self.direction
end

function flip(direction)
	sprite.set_hflip("#sprite", direction < 0)
end

function animate(action)
	if action.pressed then
		sprite.play_flipbook("#sprite", "run")
		elseif action.released then
		sprite.play_flipbook("#sprite", "idle")
	end
end

local function clamp(v, mim, max)
	if v < min then 
		return min
	elseif v > max then 
		return max
	else 
		return v 
	end
end

function fixed_update(self, dt)
	self.velocity.y = self.velocity.y - GRAVITY * dt
	self.velocity.y = clamp(self.velocity.y, -2000, 2000)
	local position = go.get_position()
	position = position + self.velocity * dt
	go.set_position(position)
	self.velocity.x = 0
end

function on_message(self, message_id, message, sender)
	if (message_id == hash("contact_point_response"))
	and message.other_group == hash(level) then
		self.ground_contact = true
		self.velocity.y = 0
	end
end

function on_input(self, action_id, action)
	animate(action)
	self.direction = (action_id == hash("right")) and DIRECTION_RIGHT or DIRECTION_LEFT
	walk(self)
	flip(self.direction)
end

They are pretty simple but checking if you have set the input bindings on the game.input_binding file and making sure you have attached the script to our player may help.
If that does not work sharing some screen shots or sharing the project could make finding the problem easier

add in print statements to see what is occurring, for example:

pprint(self.velocity) -- two p's for pretty print.
print( self.velocity.y,dt)
1 Like

input bindings are ok i think?

I would share the project but im not quite sure how i should export it

Done, hope this helps?

Could it be the fact theres an update available?

On line 62, you’re using self, but there is no self there, so it becomes nil.
You can only use the variable self, from a function with has a parameter self.

I put the print statements in the functions, should I send the project for you to look at?

Would make it easier to help

which functions? are you still seeing the same error? Could it be possible to show here the code? Better as text than as an image.