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

2022/5/26

hello I need help with this getObjectsInRange method

1
2
bañaperras bañaperras

2022/5/26

#
hello I need help with this getObjectsInRange method
Roshan123 Roshan123

2022/5/26

#
Anymore details would be great. I mean do you want to know how to use getObjectsInRange() method or is their any problem in using it?
bañaperras bañaperras

2022/5/26

#
I need help with that method because I am working with a video game and I will do the part where an object is static, the player approaches the object and the object attacks him I think that method is done, thanks for the help
Roshan123 Roshan123

2022/5/26

#
if (getObjectsInRange(70, Player.class).isEmpty()) 
//Do this
bañaperras bañaperras

2022/5/26

#
Thanks I'll implement it to see if it works
bañaperras bañaperras

2022/5/27

#
the code works for me now well it does not comply with the thing of activating the enemy when the player approaches. Do you know any method for when my player approaches an object that activates?
bañaperras bañaperras

2022/5/27

#
because that method haunts the player since the game begins and it must be when he approaches ;) thanks in advance
Roshan123 Roshan123

2022/5/27

#
bañaperras wrote...
because that method haunts the player since the game begins and it must be when he approaches ;) thanks in advance
Try decreasing the range from 70 to 10 or 20 or something like that You can also use getNeighbours()
if(!getNeighbours(20, true, Player.class).isEmpty())
Roshan123 Roshan123

2022/5/27

#
Just found the best demo for you. Hope you find it worthy!
bañaperras bañaperras

2022/5/28

#
ok,ok i will see what i do
bañaperras bañaperras

2022/5/28

#
hey please I need if you can make an object and player as an example that if you approach the object in a defined area or radius the object will chase the other player that the code is very complex and I am a beginner
Roshan123 Roshan123

2022/5/28

#
Sorry, but due to some reasons, I can't use my device for few days. If it's urgent, then you can also have a look on my BlueBot class which only moves towards the Crate class when it's on certain range in SOLO MODE ONLY.
Roshan123 Roshan123

2022/5/28

#
Leave it. You will get confused after looking into my program becaz it's way too bulky, not at all documented and poorly managed. So here is how to do it:
Actor player = (Actor)getWorld().getObjects(Player.class).get(0);
if(!getObjectsInRange(100, Player.class).isEmpty())
{
turnTowards(player.getX(), player.getY());
move(3);
}
bañaperras bañaperras

2022/5/29

#
Hello, do you know any method so that when the lives of an object are removed, it drops an object and reappears in another place and thanks for the previous code, it worked for me :)
Roshan123 Roshan123

2022/5/29

#
bañaperras wrote...
Hello, do you know any method so that when the lives of an object are removed, it drops an object and reappears in another place
For that you need to use several greenfoot methods. But just to be clear, do you mean when a object dies, it leaves back it's coffin at the same coordinate (where it died) and gets respawn in another place. Am i right or wrong? After getting your reply, I will provide you the answer accordingly
There are more replies on the next page.
1
2