Spawning bullet at certain coordinate

Get help using Construct 2

Post » Wed Apr 01, 2015 9:16 pm

I know how the image points work but I need to have a dynamic spawn point for the bullet.

How can I spawn a bullet from the center (origin) of the sprite, 100px towards the mouse pointer?
B
4
Posts: 10
Reputation: 220

Post » Wed Apr 01, 2015 9:44 pm

create bullet (player.x, player.y)
set bullet angle of motion to player.movingangle (assuming its a 8 direction movement on it)
set bullet invisible

if bullet.distance travelled > 100 -> make bullet visible
B
82
S
39
G
15
Posts: 982
Reputation: 16,712

Post » Wed Apr 01, 2015 9:49 pm

Hmm, Create bullet?

This is what I currently have:

Mouse -> Left button is down -> Player -> Spawn Bullet on layer 2 (image point 0)
System -> Every 0.1 seconds -> Bullet -> Set angle toward (Mouse.x, Mouse.y)

What I want is to get the bullet spawn 100 px away from the center of Player towards mouse pointer instead of image point 0.
B
4
Posts: 10
Reputation: 220

Post » Wed Apr 01, 2015 10:28 pm

sorry my bad, im tired.

use the "Bullet" -> Move Forward (distance 100) action after setting its angle to point at the mouse

voila!
B
82
S
39
G
15
Posts: 982
Reputation: 16,712

Post » Wed Apr 01, 2015 10:28 pm

Its in the "size and position" section of the action window
B
82
S
39
G
15
Posts: 982
Reputation: 16,712

Post » Wed Apr 01, 2015 10:34 pm

If your bullet comes from a gun sprite or something like that, you can also use an image point instead of using this method.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Wed Apr 01, 2015 10:58 pm

The math way:

Create bullet at: Sprite.X + cos(angle(Sprite.X, Sprite.Y, Mouse.X, Mouse.Y)) * 100, Sprite.Y + sin(angle(Sprite.X, Sprite.Y, Mouse.X, Mouse.Y)) * 100

You can also store the calculated angle in a local variable so you only have to calculate it once, then substitute that variable into the equations.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,106

Post » Thu Apr 02, 2015 8:09 am

How can I spawn something on a coordinate instead of image point?
B
4
Posts: 10
Reputation: 220

Post » Thu Apr 02, 2015 9:07 am

................ :)

Image
Image
B
63
S
23
G
7
Posts: 1,480
Reputation: 10,796

Post » Thu Apr 02, 2015 11:17 am

Ah, thanks. The basic tutorial told me tu use Player -> Spawn which only works with image points. Doh!
B
4
Posts: 10
Reputation: 220


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 7 guests