Search code examples
mathcoordinatesmit-scratchvisual-programming

how to make an enemy independently moved by an inverted screen movement made by the player


What I'm trying to make In mit-scratch I'm making an Isometric game with an arena as the main part of the game idea, the player would be going around killing enemies while being unable to pass through objects. the enemies should be slower than the player but should provide a challenge non the less.

problem I have succeeded in making the player appear as if it's moving across the screen and appear to hit objects, go behind them and reappear again when in front. (this is all based on the screen invertedly moving while the player stays in the center at 0,0) as the stage moves up the players' y position is less and at its max "1266" and at its least "0" since the enemy is NOT a stationary object and based on the movement of the player to determine its position, it ends up moving upward in the y axis to compensate for the movement of the player, the problem of this is the fact that when the enemy goes near an object it can hide behind, it will change layers dependent to that of the stage which causes the enemy to only go in front of objects when the player can and vise versa when the player cant. so I want the enemy to not change its y-axis when it gets further away from 0 but instead find its position on a grid and determine whether it should be in front or behind an object for itself.

game mechanics as said in the problem of the matter sprites behind objects should be hidden the way this is done, is by removing 0 from the stage by adding the max value by itself so that when it reaches the top or bottom its always positive from "0-1266" (this number is always referring to the Y axis) the player would then start at this max number/2 and x=0 so they would naturally start at 0,0 in a sense. what the pillars (objects) do is they are all clones that take the value of the stage and compare it to their own starting value and determine if they should be above the player or behind by going to the back layer and moving up a certain number of layers thus creating the illusion that the player is in the arena.

What I'm asking I'm not asking anybody who reads this to understand scratch or how it works but instead to solve the problem in a figurative sense of how you would solve it if you were doing it yourself, and then I would try to replicate your idea and hope it works.

it's very hard to visualize in my head but I've mostly played around with how the stage interacts with the y value of the player and I've mostly just tried some differencing trying to get rid of the distance from 0 from the center of the screen, so I made it figure out the distance from the player but this just did the same thing but made the center the player... and at this point, I don't know what to do... 


Solution

  • my question was satisfied by - Ruud Helderman and am providing an answer to show that my question is resolved, by this video i have been informed of: https://www.youtube.com/watch?v=bxjbYJLAUYU&ab_channel=griffpatch

    by using the sprites y axis you could determine the layer of the sprite and consistently do so using an exploit in scratch itself to figure out the layer of which it is on and be should be on.