Jump to content


Photo

change direction if theres no ground.


  • Please log in to reply
1 reply to this topic

#1 cheeseboy16

cheeseboy16

    "The Cheese"

  • Banned Users
  • 219 posts
  • Version:GM8

Posted 04 May 2011 - 07:35 PM

I want an object to turn around when it sees and edge. I wrote this code and it works the first time but after the object changes directions it goes off the other edge. What am I doing wrong?
with (footmsk)
{
    if instance_place(x-2,y,ground_default)!=noone or instance_place(x+2,y,ground_default)!=noone
    {
        grnd_exists=true
    }
    else
    {
        grnd_exists=false
    }
}

if !footmsk.grnd_exists
{
    if hspeed > 0
    {
        sprite_index=spr_flagguy_L
        hspeed=-2.6
    }
    if hspeed < 0
    {
        sprite_index=spr_flagguy_R
        hspeed=2.6
     }
}

Edited by cheeseboy16, 04 May 2011 - 07:39 PM.


#2 sneekyllama

sneekyllama

    GMC Member

  • GMC Member
  • 784 posts

Posted 04 May 2011 - 07:46 PM

For the second if statement change it to else if.

Whats happening is it changes the direction in the first if but the second if is changing it back.

if !footmsk.grnd_exists
{
    if hspeed > 0
    {
        sprite_index=spr_flagguy_L
        hspeed=-2.6
    }
    ELSE if hspeed < 0
    {
        sprite_index=spr_flagguy_R
        hspeed=2.6
     }
}

Edited by sneekyllama, 04 May 2011 - 07:48 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users