[SOLVED] How to make Actors impassable

Guzzz

  • Posts: 556
Hi to everyone!

I am making a game without physics, but my enemies and Player are moving. The Question is, can I make them impassable? So, if I make Follow Behavior for the enemies they would not go through player or other enemies. Therefore Player could not move his token through enemies or other objects. Right now they just go through each other like bunch of ghosts ;)

« Last Edit: June 23, 2014, 10:52:03 am by Guzzz »
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

sdieters

  • Posts: 2068
You can do it without collision models but it is quite a hassle since you gave to check the distance for each actor on screen. And then we haven't looked at the required CPU power...
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

Guzzz

  • Posts: 556
I am not very sure that I understand you...
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

sdieters

  • Posts: 2068
if you use normal physics with collision boxes, it is easyer then trying to build it without collisions because you have to check where all the actors are by code.

perhaps you can explain me what you mean with "without physics"?
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

Guzzz

  • Posts: 556
Sorry, I didn't make my situation very clear. What I meant is that my game is top-view and I don't use gravity. I also don't build stuff in the scene design window. Everything is in code. I guess I still can use physics with collision.

I have several enemies that appears by random and they attack player. So they have to follow player, which they do, but I don't need them to go through Player or other enemies.

The problem is that all the examples I've seen so far are enemies with 1 HP which means that they die right after they hit Player. So they don't have time to go through Player. In my case enemies have more than 1 HP.  BTW even with the example  when enemy dies when hits a target, they (enemies) still don't have collision with each other and they go through each other.
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

sdieters

  • Posts: 2068
so if i am correct, you just want to make sure it looks good when they try to go after the player, by not letting them go trough each other.

in that case you can make it as complicated as you want. the most simpel way is making sure that the collision group can collide with their own group and the player (enemy group can colide with enemy and player), so they bump into each other.
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

Guzzz

  • Posts: 556
That was simple! Thanks! I was sure that I checked all the groups.
Now they are bouncing! Awesome!  :)
Now I have another problem. They look like balloons. I need them to stop when they (enemies) reach Player, and Player shouldn't push enemies.
I did the "Follow the Target" by the code that you can see in the attachment.  Now I need to do something with the force the got when they "pushed" to Player... or simply stop them... but then I need them to start to move over again when Player starts to move. I need logic similar to something like this http://www.stencyl.com/game/play/3670   but without placing  all of them in a scene screen window which I have to do if I want to use pre-installed Follow the Target behavior.
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

sdieters

  • Posts: 2068
asuming that your distance attribute is the distance between your enemie and your player you can use that to set a bool which checks if you are next to the player.

chasing = boollean attribute

if distance > (the distance you want to keep between the enemy's and the player)
~set chasing to true
else
~set chasing to false

now wrap your whole moving code inside an IF statement which only gets executed if "chasing" is true
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

Guzzz

  • Posts: 556
Wait. How they will chaise? In the screenshot above I showed how I tried to change pre-installed Follow the Target behavior, which didn't work out. Actually right now I use other code (in the attachment). Should I call this code by "chaise" and use your stroke as a switcher for this code?
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

Guzzz

  • Posts: 556
In order to use distance attribute I need to find the distance in the first place, right? How to find this distance?
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

sdieters

  • Posts: 2068
if you want to do a simple survival game in which you spawn enemy's that will walk towards your player, it can be done very easy. the only things you need to change iin that last code is this:

target = actor attribute
minDistance = number attribute (this is the minimum distance that the enemie must keep between him and the player. set this in the behaviours tab of your enemy)
angle = number
wlakSpeed = number

when created
set health points to 4
for each (actor of type) (Player)
~set target to (actor of type)

always
set angle to ((atan2 (y: ((x-center of self) - (x-center of target)) x: ((x-center of self) - (x-center of target)))as degrees)
if (sqrt((x-center of self - x-center of target )^2 + (y-center of self - y-center of target )^2)) > minDistance
~set velocity to (dir: (angle) degrees, speed: (walkSpeed)) for self
otherwise
~set velocity to (dir: (angle) degrees, speed: 0) for self

if i forgot something, let me know. i had to go all of the sudden.

Good Luck!
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

Guzzz

  • Posts: 556
Thank you very much for a such detailed reply!
I did what you described but it says: Unknown identifier and make the last stroke with "otherwise set velocity..." in red.
Did I make a mistake somewhere?
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

Guzzz

  • Posts: 556
Ok! I found some errors in my code and now it works perfectly! It does what I want. Thanks again, man!
The topic isn't solved though.
Now enemies follow Player and stop when he stops. They also don't go through each other and Player. The only problem is Player can push enemies which isn't good. I can turn the bullet "Cannot be pushed" in the Physics on, but they will act as ghosts again (walk through and overlapping each other). How I can prevent Player to push enemies?

BTW here is the corrected code:
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

sdieters

  • Posts: 2068
the bullet should be normal physics, but the collision should be a trigger. as for the player pushing the enemies, try setting the enemies to cannot be pushed.
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

Guzzz

  • Posts: 556
If I turn the enemies to cannot be pushed they will start to walk through and overlapping each other, and Player will able to go through them. I don't need that. I need them to have this Normal physics but without been pushed by Player.
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/