I am Sorry, I’m not used to in forum before, so here is my code it’s refering to your answer.
function init(self)
msg.post(".", "acquire_input_focus")
self.moving = false
self.firing = false
self.input = vmath.vector3()
self.dir = vmath.vector3(1, 0, 0)
self.speed = 400
-- save position
self.position = go.get_position()
self.velocity = vmath.vector3(0, 0, 0)
msg.post("#", "reset")
end
This is the part I suspect that might be the cause of my problem
function update(self, dt)
if self.moving then
local gravity = vmath.vector3(0, gravity, 0)
local pos = go.get_position()
pos = pos + self.dir * self.speed * dt
go.set_position(pos)
end
if self.firing then
local angle = math.atan2(self.dir.y, 0)
local rot = vmath.quat_rotation_z(angle)
local props = { dir = self.dir }
factory.create("#bulletfactory", nil, rot, props)
end
self.input.x = 0
self.moving = false
self.firing = false
if not self.ground_contact then
self.velocity = self.velocity + gravity
self.position = go.get_position()
end
go.set_position(go.get_position() + self.velocity * dt)
self.correction = vmath.vector3()
self.ground_contact = false
end
and this is my reset looks like
if message_id == hash("reset") then
self.velocity = vmath.vector3(0, 0, 0)
self.correction = vmath.vector3()
self.ground_contact = false
self.anim = nil
go.set(".", "euler.z", 0)
go.set_position(self.position)
msg.post("#collisionobject", "enable")
msg.post("camera", "enable")
elseif message_id == hash("contact_point_response") then
if message.group == hash("danger") then
msg.post("camera", "disable")
go.animate(".", "euler.z", go.PLAYBACK_ONCE_FORWARD, 160, go.EASING_LINEAR, 0.7)
go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, go.get_position().y - 200, go.EASING_INSINE, 0.5, 0.2,
function()
msg.post("#", "reset")
end)
elseif message.group == hash("geometry") then
handle_geometry_contact(self, message.normal, message.distance)
end
end
end
Yeah I can’t more agreed with you sir. britzl but it’s my first time I build a game and this is the first time I use my logic for something else, well, I am not majoring in anything but sometime ago I learned android studio, but it feels like making some game is a whole new level for me. But, thank you for supporting us. and after this done I am going to learn the basic lua programming, well, I am that type who can’t let go if I left something undone and yeah sometime I work like that too, using my logic. but so far it’s no luck, sob.