This site requires JavaScript, please enable it in your browser!
Greenfoot back
EthanWasHere_
EthanWasHere_ wrote ...

2019/4/9

getting a character to shoot the way im aiming

EthanWasHere_ EthanWasHere_

2019/4/9

#
so basically I'm trying to make a 2D fighter like street fighter in green foot but the when I try and make the player 1/2 shoot they both only shoot in 1 direction even though im facing the other one, how would I fix this? here's my code so far:
        if (player1.facingLeft == true)  
        {
            move(-5);
        }
        else
        {
            move(5);
        }
danpost danpost

2019/4/9

#
You need to show your codes around which you add the shot into the world. However, if you did a search, I am sure you will find something in the discussions to help.
EthanWasHere_ EthanWasHere_

2019/4/10

#
yeah i have searched and so far haven't found anything that has worked also here is the shoot code (also the code above is in the laser class and this shooting code down below is in the player1 class):
     public void checkkeys()
    {
        shootCounter++;
        Laser Laser = new Laser();
        Laser.setRotation(getRotation());
           
        if (shootCounter >= shootSpeed && Greenfoot.isKeyDown("1"))
        {
            
            getWorld().addObject(Laser, getX(), getY());
            shootCounter = 0;
        }
        else if(shootCounter >= shootSpeed && Greenfoot.isKeyDown("1"))
        {
            
            getWorld().addObject(Laser, getX(), getY());
            shootCounter = 0;
        }
      
    }
i also have this helping it:
    
    int shootCounter = 0;
    int shootSpeed = 30;
and this:
      public boolean touchingBullet()
    {
       return isTouching(Bullet.class);
    }
Super_Hippo Super_Hippo

2019/4/10

#
The act method of the bullet (or in your case the laser) should only be moving straight and maybe detect collisions. Since its rotation is set at its creation, you don't need to check in which direction it should travel. Your "else if" is exactly the same as the "if" before, so it will never do anything.
You need to login to post a reply.