Help me figuring out how to place object relative to player position and its start position.

Edwin

Member
Hello, people. I'm trying to make Castle Crashers like movement by creating a ground objects (slope, basic blocks, etc.) and moving them into player's vertical position every tick but they should move relative to their position too, not only the player position, otherwise they will aligh in the line which is not good. I need to make it because the game itself will have not only one, but several vertical "floors" or something that player will reach by jumping or just simply walking up the stairs.

This is what I expect:


How to implement that?
 

NightFrost

Member
I'd probably just do a free movement scheme and use an invisible collision object to create boundaries (basically the green boundary edges in your example). Quite a few games, I recall, don't treat stairs anything special. They're just walkable terrain with different visuals and they create a bend to the area where player is allowed to move. If you want the stairs to alter movement, stretch another object over them and check for collision. If there is a stair collision, use an alternate movement scheme.
 

Edwin

Member
I'd probably just do a free movement scheme and use an invisible collision object to create boundaries (basically the green boundary edges in your example). Quite a few games, I recall, don't treat stairs anything special. They're just walkable terrain with different visuals and they create a bend to the area where player is allowed to move. If you want the stairs to alter movement, stretch another object over them and check for collision. If there is a stair collision, use an alternate movement scheme.
This doesn't answers my question. I need to move these red and blue objects which will later do collisions, but simply moving them using
Code:
y = object_player.y;
will make them work like this:

Imagine what happens if my player and ground objects will collide to each other (right now my player just moves up when player's x < ladder x and > ladder x), so I need to move the ground relatively the player and it's current position.
 
Last edited:

Homunculus

Member
Not sure if this may be a good idea or not since I haven't been using them for a while now, but couldn't you base your "floor" collisions on a path? You define a generic path for the whole stage and have your instances follow it forwards or backwards relative to the player y position. Walls that require jumping could stop the player by defining a maximum angle for the path to be followed by simply going forward, so that having a 90deg change in direction actually stops the movement.

As said, I'm not so sure this could actually work for every use case you require, but it's worth considering.
 

Edwin

Member
Not sure if this may be a good idea or not since I haven't been using them for a while now, but couldn't you base your "floor" collisions on a path? You define a generic path for the whole stage and have your instances follow it forwards or backwards relative to the player y position. Walls that require jumping could stop the player by defining a maximum angle for the path to be followed by simply going forward, so that having a 90deg change in direction actually stops the movement.

As said, I'm not so sure this could actually work for every use case you require, but it's worth considering.
I have no idea what are you talking about I just need to calculate ground's Y position to place it relative to player.
 

Homunculus

Member
What I’m saying is that you could use a path in order to keep track of the general layout of the level and the current floor y position and avoid the problem to begin with.

If you want to stick to moving floor objects, you should probably keep an arbitrary variable that stores the current player position on the floor. Just using y as you noticed can’t work, imagine the mess you’ll get into when jumping for example. Keep a separate “y” variable that’s under your control, and bind it to your uo / down keys or movement code.

The reason i’m suggesting a different approach though is that even if you get this working, you’ll need to figure out a way to have a different floor or check for every enemy / friend instance on the screen.
 
Last edited:

Edwin

Member
What I’m saying is that you could use a path in order to keep track of the general layout of the level and the current floor y position and avoid the problem to begin with.

If you want to stick to moving floor objects, you should probably keep an arbitrary variable that stores the current player position on the floor. Just using y as you noticed can’t work, imagine the mess you’ll get into when jumping for example. Keep a separate “y” variable that’s under your control, and bind it to your uo / down keys or movement code.

The reason i’m suggesting a different approach though is that even if you get this working, you’ll need to figure out a way to have a different floor or check for every enemy / friend instance on the screen.
Thanks for answering.

It's just an idea how platformer game could become a beat em up game. For other instances like enemies I could create same count of ground objects as for player and give them the same functions.
 

samspade

Member
I think the reason you're getting answers that don't answer your initial question is that your initial question is hard to understand. Having read it a couple times, I'm not sure I know what you're asking.

What does: "they should move relative to their position too, not only the player position, otherwise they will aligh in the line which is not good" mean?

You can't have it both ways you either align them to the player or you don't. Do you mean you just want to align one axis? Something else? Is it that you want some of them to have an offset from the player or an offset from some other portion?

Also, it honestly seems a little more complicated than it needs to be. Couldn't you accomplish the same thing by simply having adding or subtracting from the player's y position while moving left or right on the stairs (respecting collision with the green obstacle)?
 
Top