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
Hard to tell what’s wrong. Can you double check that all scripts are added? Also double check collision groups and masks. Another thing to try is to set a breakpoint on the first line of the on_message function and see if it gets called at all.
That looks better, but the game object is scaled and the runtime shape doesn’t look like in the editor. The explanation can be seen when we look at the shape itself:
The shape is 20x20 pixels, which corresponds to what we see at runtime. The size of collision shapes aren’t scaled with the game object scale (there’s a ticket for this, but it’s not at the top of our list). You should set the size of the collision shape directly on the shape.
@Erik_Angelin and @mats.gisselson: We need to make sure that the editor doesn’t scale the shapes. I’ll create a ticket.
No, currently no way to prevent that, but the issue I linked should make sure that the visualisation in the editor matches the behaviour of the engine.