Hello,
Today I am trying to create a jumping mechanic and I am a bit lost. I do not know exactly how I would do it. I have looked at many different posts and assets and I am still lost. Here is what I have…
local min_y = 30
local max_y = 680
local min_x = 30
local max_x = 1225
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
self.vel.x = 0
self.vel.y = -200
if pos.y < min_y then
pos.y = min_y
elseif pos.y > max_y then
pos.y = max_y
end
if pos.x < min_x then
pos.x = min_x
elseif pos.x > max_x then
pos.x = max_x
end
go.set_position(pos)
self.vel.x=0
end
function on_message(self, message_id, message, sender)
--Handle collision
if message_id == hash("contact_point_response") then
--local newpos = go.get_position() + message.normal * message.distance
--go.set_position(newpos)
self.vel.y=0
end
end
function on_input(self, action_id, action)
if action_id == hash("up") then
self.vel.y = 400
elseif action_id == hash("down") then
self.vel.y = -400
elseif action_id == hash("left") then
self.vel.x = -400
sprite.set_hflip("#sprite", false)
elseif action_id == hash("right") then
self.vel.x = 400
sprite.set_hflip("#sprite", true)
elseif action_id == hash("down") then
self.vel.y = -400
end
end
Now I don’t quite know how to implement a jump, and I have read over multiple posts and I still feel lost…
Eventually, I would like to be able to add double jumps and wall jumps, but I can’t even get a normal jump haha.
If anyone could take a look at my code and let me know what I can add and/or tweak with what I have it would be greatly appreciated.
Also, I have taken a look at platypus and it seems extremely convenient (and I would love to use it) but I’m not quite sure how it works. I have added the library dependancy and copied and pasted in the code that was listed under usage at this site. If anyone has insight on using platypus or creating my own code or directing me with platypus it would be very appreciated
(sorry for all the questions lately, I have just been a bit lost.)