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

2018/5/16

Spawn actor a certain distance from other actor

Prox276 Prox276

2018/5/16

#
Is there a way to set an offset from an actor where another actor will spawn when using the addObject command? I'm making an astronaut game and the astronaut has a gun, but the bullets shoot out of his head, instead of out of his gun.
danpost danpost

2018/5/16

#
You can make any initial adjustments in the position/rotation of the bullet when you create it. For example to have bullet start 10 up and 5 forward (with respect to orientation of the astronaut):
Actor bullet = new Bullet();
getWorld().addObject(bullet, getX(), getY());
bullet.setRotation(getRotation());
turn(90);
move(10);
turn(-90);
move(5);
Prox276 Prox276

2018/5/16

#
Ok, thank you
Prox276 Prox276

2018/5/16

#
okay, but how do I make it so the commands will only get executed once?
danpost danpost

2018/5/16

#
Prox276 wrote...
okay, but how do I make it so the commands will only get executed once?
I am not sure what you mean. Show how/where you used it (with context).
Prox276 Prox276

2018/5/22

#
Oh, I've already found it out myself. Thanks
You need to login to post a reply.