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

2021/10/20

Objecting moving towards another roughly

xixEmilyxix xixEmilyxix

2021/10/20

#
Hi, id like to make my bee object move towards my flower object roughly (going off course a little bit on the way) i have basic code to move the bee which is this:
    public Bee()
    {
    }
   
    public void flyAround()
    {
        //go forward
        move(1);
        //turn randomly
       if(Greenfoot.getRandomNumber(100) < 5)
        {
            turn(Greenfoot.getRandomNumber(20) - 15);
        }
        //if hit side, turn
       if(getX() <= 5 || getX() >= getWorld().getWidth() - 5)
        {
           turn(1); 
        }
        //if hit side, turn
       if(getY() <= 5 || getY() >= getWorld().getHeight() - 5)
        {
            turn(1);
        }
    }
}
danpost danpost

2021/10/20

#
I guess you could add another random turn with a greater chance and maybe a bit more turn to zero in on a flower. You would need to know which way to turn depending on where the flower is with respect to the bee.
xixEmilyxix xixEmilyxix

2021/10/20

#
How do i make it go target a flower though?
danpost danpost

2021/10/20

#
xixEmilyxix wrote...
How do i make it go target a flower though?
You may want to look at my Zombie Shooter Demo scenario. The zombies, when in range, slowly turn toward the player. The mechanism might give you ideas on how to accomplish what you want, at least as far as knowing which way the bees should turn.
xixEmilyxix xixEmilyxix

2021/11/3

#
danpost wrote...
xixEmilyxix wrote...
How do i make it go target a flower though?
You may want to look at my Zombie Shooter Demo scenario. The zombies, when in range, slowly turn toward the player. The mechanism might give you ideas on how to accomplish what you want, at least as far as knowing which way the bees should turn.
Hi, im reading through it to see how it works and im confused what the 'getQR' part is? This is in the chaser part on the line:
move(rate/8, getQR());
danpost danpost

2021/11/3

#
xixEmilyxix wrote...
im confused what the 'getQR' part is? This is in the chaser part on the line:
move(rate/8, getQR());
getQR is a method in the QActor class. I could (maybe should) have named it getQRotation). It returns a precision rotation value where getQR()/QVAL (automatically rounded down to an integer) gives the same value as the Actor class method getRotation would. The getQR method in the QActor class is documented; so, take a look. The move method is also in the QActor class (check it out, also). It takes the distance to move and the (precise) angle to move in and moves the actor with precision.
xixEmilyxix xixEmilyxix

2021/11/3

#
ooooh thank you
xixEmilyxix xixEmilyxix

2021/11/12

#
I have looked at it for a while now and still can't figure out how to make my bee move towards to flower. I'm completetly lost. Any tips on how to make it move towards a flower?
danpost danpost

2021/11/13

#
xixEmilyxix wrote...
I have looked at it for a while now and still can't figure out how to make my bee move towards to flower. I'm completetly lost. Any tips on how to make it move towards a flower?
You need to show what you have tried so we have something to work off of.
xixEmilyxix xixEmilyxix

2021/11/13

#
All i have is my standard move code which just randomly goes around the screen. I don't know how to target an actor
danpost danpost

2021/11/13

#
xixEmilyxix wrote...
All i have is my standard move code which just randomly goes around the screen. I don't know how to target an actor
Try something. You have already seen codes in the demo -- in the act method of the Chaser class. The only thing you might want to change is the amounts of change in turn and speed as the distance decreases between the two actors.
xixEmilyxix xixEmilyxix

2021/11/13

#
like i should put the code into my one and see how it works?
danpost danpost

2021/11/14

#
xixEmilyxix wrote...
like i should put the code into my one and see how it works?
That would be a start.
xixEmilyxix xixEmilyxix

2021/11/14

#
sorry and thank you , ill try that
You need to login to post a reply.