My character is falling off a platform(I followed the runner
the “controller” collision type is static, group: geometry, Mask: player
“player” collision type is kinematic, group: player, mask: geometry
tried to remake it again still falling
local gravity = -20
local jump_takeoff_speed = 900
local jumping = false
function init(self)
msg.post(".", "acquire_input_focus")
self.position = go.get_position()
self.velocity = vmath.vector3(0, 0, 0)
self.ground_contact = false
end
function final(self)
msg.post(".", "release_input_focus")
end
function update(self, dt)
local gravity = vmath.vector3(0, gravity, 0)
if not self.ground_contact then
self.velocity = self.velocity + gravity
end
go.set_position(go.get_position() + self.velocity * dt)
self.correction = vmath.vector3()
self.ground_contact = false
if self.teleport == true then
self.position = vmath.vector3(150,self.position.y,self.position.z)
go.set_position(self.position)
end
self.teleport = false
end
local function handle_geometry_contact(self, normal, distance)
local proj = vmath.dot(self.correction, normal)
local comp = (distance - proj) * normal
self.correction = self.correction + comp
go.set_position(go.get_position() + comp)
if normal.y > 0.7 then
self.ground_contact = true
end
proj = vmath.dot(self.velocity, normal)
if proj < 0 then
self.velocity = self.velocity - proj * normal
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
-- check if we received a contact point message. One message for each contact point
if message.group == hash("geometry") then
handle_geometry_contact(self, message.normal, message.distance)
end
end
end
local function jump(self)
if self.ground_contact then
self.velocity.y = jump_takeoff_speed
jumping = false
end
end
function on_input(self, action_id, action)
if action_id == hash("jump") then
jump(self)
if jumping == false then
msg.post("#sound", "play_sound")
jumping = true
end
elseif action_id == hash("teleport") then
self.teleport = true
end
end