BulletTime: Straight Shooting

1

Stats

6,548 visits, 9,441 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 5 Dec, 2011. Last updated 19 Feb, 2019

In another tutorial it showed how two sprites could be put together to make a sort of turret. The base was could move and the gun attached would stick to it while rotating to aim at the mouse. This isn't very useful without an actual projectile to fire. So, this tutorial will show how to generate bullets.

The first thing to do is add a Bullet sprite onto the layout. I have this red ball which I resized to 10 x 10 pixels to fit my Gun sprite. It would look strange to have a bullet bigger than the barrel of your gun. I also put it outside the visible window of the game so that the bullet doesn't show up when the game first loads.

Next we need to add behaviors to this Bullet.

The bullet behavior was added, plus the destroy outside layout. This will make sure when the Bullet sprite leaves the layout it disappears, and the computer doesn't keep calculating where it should be.

One more piece of setup that needs to be done is to create another image point for the Gun. Go into edit the sprite and add an image point.

I called it "Shooting" and placed it at the end of the barrel where the bullets will appear.

Now let's add some events.

So what's going on here is when the left mouse button clicks the system will create a Bullet object at the "Shooting" image point we put on the Gun earlier. (Note that because the image point isn't a variable it needs quotation marks around it. Otherwise, you could also use the number for that image point instead, without quotations. In our case it would be 1.)

Now if you test it Bullet sprite will generate at the tip of the Gun every time you click, but something seems off. It doesn't aim where the Gun is aiming. This is because the Bullet has it's own angle and it isn't the same as the Gun angle.

This action needs to be added to change that.

This sets the Bullet angle to the angle of the Gun right after the object is created.

Now if you test it everything should work as you think it should.

Various Ways to Use: Beginner

Tanks and turrets

Fire away!

Arched shots

We added bullet behavior to the Bullet sprite. Built into Construct is are parameters of the bullet behavior which can be changed on the left-hand menu if you click on the Bullet sprite.

You can change the speed and gravity that affects the Bullet, and by doing so you can make the shot arch like a basketball.

Various Ways to Use: Advanced

Charge shot

If the mouse event was split up into left button down and left button release it can set up a charge shot. While the button is down the Bullet generated could have a speed of zero and grow in size. And when the button is released it will change its speed.

Shot delay

With some games you might want unlimited rapid fire shooting, but to add some difficulty a shot delay could be useful. By adding a toggling variable and a wait action it is possible to only shoot once every half a second rather than every click.

Limited ammo

Unlimited ammo is great for some shooters. For others restricted ammo builds up more tension. Add a variable that changes for ever shot fired and when ammo is picked up.

  • 0 Comments

Want to leave a comment? Login or Register an account!