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

2016/10/19

How Do You Make 2 Actors Rotate And Position Together?

Sellion Sellion

2016/10/19

#
I've begun to make a game as a project, and I've come to a problem. The concept of it is a top-down shooter, with the main character holding out a gun. I want it so that when I press the shoot button, a bullet discharges from the end of the gun. Currently, I have it set up to where it shoots from the middle of the main character. All attempts to move where the bullets comes from have failed. The character moves their direction towards the mouse, and so does the bullet when it leaves, however, I am not able to set the bullet to leave at the end of the gun. I'd like to know a way where I can set an actor on the end of the gun, and when the game starts, it stays where it's at, turning and moving while staying exactly where it was located on the main character when it was first placed. To rephrase, I would like a way to basically combine two actors to turn and move like one single object, but be able to discharge the bullet from the point I chose.
danpost danpost

2016/10/19

#
The main actor should have a reference to its gun and control its location. That is, set location to (getX(), getY()), set rotation to 'getRotation()', move some distance out from center of main actor, turn(90), move some distance sideways, and turn(-90). Doing this at the end of every act cycle (after the main character has moved and turned) will keep the gun in place. The gun object should create the bullet objects and add them into the world, initializing their rotations and placement in a similar fashion (except not continuously).
You need to login to post a reply.