Help I making runner game into some kind metal slug and got troubled

Uh, thanks for intend to help me.

so I tried to making game with combined war battles script to decide my character direction in my case I need it to decide which way my character aim his shoot.

and I still use default reset from runner the first tutorial how to die and reset.

but it seems like doesn’t quite right because the war battle direction is changing my saved character position, I am seeking forum and there’s no one had any problem like me, sob.

is it any way for me to saved the initial position or ways to make it better ? because I ran out time and deadline, lol every body just depens on me with these project.

thanks,

2 Likes

It’s very hard to give any specific advice since you haven’t shared any code. What do you mean exactly by “saved the initial position”? When do you wish to save the initial position? Like this:

function init(self)
     self.pos = go.get_position() -- save initial position on start
end

Or:

function on_input(self, action_id, action)
   if action_id == hash("some_action") and action.pressed then
       self.pos = go.get_position() -- save initial position on input
   end
end

This is rarely a good way to learn something new. Rushing things and stitching together code from multiple places without actually understanding what it does only ends in tears. You need to understand the basics of Lua (or any programming language for that matter). Then try to describe your game logic in clear and discreet steps. Start by writing text, not code. Next think about how to translate these steps into code. Keep the text as code comments! Also think about where to put your logic. Is it something that should happen once? If yes, then put it in the init() function. Should it happen on input, then stick it into the on_input() function. Every frame? Put it in update(). And so on. Good luck!

3 Likes

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.

1 Like

Thanks. And what was the problem again?

Everytime my character dies it didn’t move to a start point like it should, but it continues died in same place. So I can say that after I decide I had to define my character direction (self.move) and put that self move to update so my saved position changed everytime in order to decide my character direction. Because if I roll back the script to the old one (without direction) it run fine. So I am curious is it another way around to make them in friendly-term…