Simple Boolean Question.. not for me though


(Nate ) #1

Okay guys! I am back again… there is a surprise!

Anyway, really simple brief run down, I have a level, hero, blocks and now a moving enemy. The enemy starts moving left, and when the enemy hits a block it turns around and moves the other way. The problem is, when it hits a block again it goes through it. I think I need another boolean or I am using the switch like set up incorrectly. I know there are basic switch boolean formulas, but I wanted to see what you guys thought, here is all the update code for my enemy! Let me know what you think, the boolean starts as false. :dancer:

if (isHit == false)//if false move left
			{
				x -= power;
			}
			
			
			if (isHit == true)//if true move right
			{
				x += power;
			}
			
			
			
			if (collide("wall", x,  y) && isHit == false)
			{
				isHit = true;
				
			}

(TheHuckleberryWill) #2

Pretty sure you need another collision one

			if (isHit == false)//if false move left
        {
            x -= power;
        }


        if (isHit == true)//if true move right
        {
            x += power;
        }



        if (collide("wall", x,  y) && isHit == false)
        {
            isHit = true;

        }
		
		if (collide("wall", x,  y) && isHit == true)
        {
            isHit = false;

        }

(Instead of isHit == true/false, you could do isHit/!isHit)


(Nate ) #3

I did try this combination already, which is what made sense to me at first too, but it makes the enemy just blow through everything! lol D:


(Zachary Lewis) #4

I moved 4 posts to a new topic: How can I spawn butterflies?


(David Williams) #6

You might want to just try checking for collision to the left or right with this setup. Ex:

    if (isHit == false)//if false move left
    {
        x -= power;
    }


    if (isHit == true)//if true move right
    {
        x += power;
    }



    if (collide("wall", x - 5,  y) && isHit == false)
    {
        isHit = true;

    }

    if (collide("wall", x + 5,  y) && isHit == true)
    {
        isHit = false;

    }

(Nate ) #7

Okay thank you so much! The enemy code you gave me solved it! As well as the butterfly code! My issue now is I would like the butterfly to stay inside of the level!