lundi 20 février 2017

What's a more efficient way to do collisions?

Here's my dilemma

I have 4 walls around the stage of my game, when a player hits these walls I do not want to make an if statement for each and every one of the walls checking if the player is hitting it, so I have created an array to hold the walls, then check if the player is hitting that. Now, because I am doing this I will not know what the player is actually hitting if he hits something, and I cannot do a check in my array if he's hitting like [0], [1], [2] etc because then I'm back to doing the checks if he's hitting specific walls. The reason I don't want to do that is for the future, when I add more barriers, buildings, and so on.

So my question is, how can I do collision checks, without hard coding checks on specific objects, and giving some sort of value that can be used for the player to respond to, for example if your hitting the top wall and you can figure that out somehow without doing the above, then make it so you can't walk through or something,

if (main.playerPosKeeper_mc.hitTestObject(this[main.StageCollisions]))

StageCollisions is an array which contains all of my barriers in it.

When the player hits anything in StageCollisions, I cannot just simply subtract from his y value, or x value, because I do not know which object he hit, but I also do not want to hard code it so that I check if I'm hitting lets say the top barrier, because then why do an array in the first place if I'm just going back to making static if else statements.

^^ Refrencing this topic

AS3 - How to Cycle States of Character Animations (moving & stopped)

This has been stumping me for a little while, so help would be greatly appreciated. It is a hard question to form so I can clarify points if necessary.

Aucun commentaire:

Enregistrer un commentaire