I’m trying to make the character move, when I put its collision in Kinematic, he does what the script says, but it keeps floating
When, I put the collision in Dynamic, the character suffers the actions of gravity, but he not does what the script says
The script I wrote:
function init(self)
msg.post(".", “acquire_input_focus”)
self.moving = false
self.input = vmath.vector3()
self.dir = vmath.vector3(0, 1, 0)
self.speed = 1000
end
function update(self, dt)
if self.moving then
local pos = go.get_position()
pos = pos + self.dir * self.speed * dt
go.set_position(pos)
end
self.input.x = 0
self.input.y = 0
self.moving = false
if self.moving then
local pos = go.get_position()
pos = pos + self.dir * self.speed * dt
go.set_position(pos)
end
end
function on_input(self, action_id, action)
if action_id == hash('Up') then
self.input.y = 1
print("up")
elseif action_id == hash("left") then
self.input.x = -1
print("left")
elseif action_id == hash("right") then
self.input.x = 1
print("right")
end
if vmath.length(self.input) > 0 then
self.moving = true
self.dir = vmath.normalize(self.input)
end
end
function final(self)
msg.post(".", "release_input_focus")
end
I put this in my code:
function init(self)
self.correction = vmath.vector3()
end
function update(self, dt)
self.correction = vmath.vector3()
end
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
if message.normal.y == -1 then
self.ysp = 0
end
if message.distance > 0 then
local proj = vmath.project(self.correction, message.normal * message.distance)
if proj < 1 then
local comp = (message.distance - message.distance * proj) * message.normal
go.set_position(go.get_position() + comp)
self.correction = self.correction + comp
end
end
end
end