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

2013/1/10

Method for placing adding objects to world a given radius from an object

camsterb camsterb

2013/1/10

#
I am looking to create an object at a set distance from the centre of another object, whose exact position is determined by the getRotation() of the central object. In my case, a hockey player's puck is created in the direction he is facing, but far away enough so that he doesn't collide with it and interact.
danpost danpost

2013/1/11

#
If creating the hockey puck from within the Player class:
Puck puck = new Puck();
getWorld().addObject(puck, getX(), getY());
puck.setRotation(getRotation());
puck.move(20); // whatever distance
puck.setRotation(0); // if neccessary
camsterb camsterb

2013/1/13

#
Thank you for your advice. The big problem I was really having was that the hockey player would always interact with the puck once it was created, causing him to pick it up again immediately after he shoots. I used a delay (counter) after shooting the puck so that he couldn't pick it up again within a short interval. You've helped me out a few times with the game and I think it'll be finished tomorrow, so I'll post a link and maybe you can let me know what you think! It's just a college project. Only been programming for about 2 months now. But do as you wish! Might give you some satisfaction knowing you helped make it that little bit! (More than you realise since I've seen your year+ old replies on other discussions that have helped me!)
You need to login to post a reply.