Parenting problem (SOLVED)

Hello,
Got a problem. In the game i am making i got a platform which is constantly moving up (until it reaches a point when it gets destroyed).
The platform itself is a Factory object (due to it spawning constantly) (something akin to infinite runner games).

Anyhow, I would like some spikes to shoot out of the platform but i got the following problem. When i try to use an animator, well he checks the current coordinates and then keeps an object in a “loop” of his original coordinates so it is not possible to move it up by using an update anymore. I would have to move the parent so the child can have its separate movement.

1.) First method i tried
If i try to move an image that is part of that factory game object i created, it doesn’t have the position property (since it is not an GO), so even tho it is moving with the platform i can’t do anything additionally to it

go.animate(url, "position.y", go.PLAYBACK_LOOP_PINGPONG, 0.0, go.EASING_INOUTBACK, 3)

2.) I tried making the spikes themselves a separate GO and then parent them with

msg.post("sp_spikes", "set_parent", { keep_world_transform = 1 }) 

but this does absolutely nothing. Maybe because i am trying to parent it to a factory? i get no error or anything so at least i know it parented it to SOMETHING but obviously not to what i wanted.

3.) Tried for the test of it to make a fully separate object with its own script. If i do its own update to move up, and an animator it will be stuck in the animator loop (animator will always override its position)

I mean these two are the only methods that come to mind at the moment, is it possible to do it in the same direction?

I move the platforms this way

function update(self, dt)
	local pos = go.get_position()
		
	if pos.y > 1200 then
		go.delete() 
	end
	pos.y = pos.y + self.speed * dt
	go.set_position(pos)
end

TLDR: The thing i need is a way to somehow parent spike trap to another game object (its parent) and which is currently a factory, so that i can use go.EASING_INOUTBACK on the spike trap
halp and ty :smiley: will post additional code/explanation if this is not enuff

EDIT: additional info, both factory objects are kinematic, i mean their GO counterparts have kinematic phy attached to them. one of them can be trigger tho i tried didn’t change much :smiley:

To use the “set_parent” message the way you want, you need to specify what object you want to be the parent. If you check the documentation, it has examples of how to use it, like so:

msg.post("my_instance", "set_parent", {parent_id = go.get_id("my_parent")})

It also says “If no parent is specified, the instance will be detached from any parent and exist in world space”, which is what your code would do. You need to put the id of the parent game object in there.

Do you want the spikes to actually shoot out of the platform, like projectiles, or do they just pop up above the surface and then go back down?


Also, just to clear up some terms.

  • A ‘Factory’ is not an object, it’s a ‘Component’ that is on a ‘Game Object’. Like all components, it’s “non-physical”, it can’t have any children of its own. A Factory component basically just pre-loads a file so you can quickly spawn it into your game at runtime.

  • A ‘Game Object’, is a “physical” thing. It can have child ‘Components’ or child ‘Game Objects’, which it will carry around with it when it moves. That’s the only thing a game object does by itself, but you can add any number of Components to it (Scripts, Factories, Sprites, etc.) to add functionality.

I’m not trying to pick on your language :smiley: , it will just be easier for you to use Defold and talk about it if you are clear on the difference between game objects and components.

4 Likes

I could never consider advice as “picking up on my language” since it is one of the things I am bad at and need to work on so all the advice is welcome and please do it again should you see me falter :D.

The code now works correctly, I was watching an example guide (my mistake) and never noticed this parent_id parameter since it wasn’t used there (and obviously that the nil detaches it to world space)
This was what i used

This is now the correct code for it:

msg.post(".", "set_parent", { parent_id = message.id }) 

Thank you for the help and advice!

3 Likes