Create a mouse jitter

Get help using Construct 2

Post » Wed Apr 25, 2012 12:19 pm

Hi, I want to create a jitter in the mouse position for a shooting game I'm making, just to make it a little tougher. I know it'd be a simple case of setting the mouse X and Y coordinates to a small random change but I can't find a way to do this in events and actions.

I've added a MOUSE object but the only option I've got in the ACTION section of EVERY TICK is to set the mouse cursor style, not the position as I'd like.

Can anyone point me in the right direction?

Thanks.vandinz2012-04-25 12:21:58
B
19
S
5
G
4
Posts: 208
Reputation: 3,960

Post » Wed Apr 25, 2012 1:07 pm

I would just make the cursor invisible, and use a sprite set position to the mouse x,y. For the jitter set the sprite position to mouse + random(-10,10).
You'll probably want to use a variable, like if variable = this set position, variable = that set position + random.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Wed Apr 25, 2012 1:47 pm

I had my mother come round while the reply was open haha - what the post above this says.

I made a quick example, I'll upload later, you can set a random offset to the mouse to point the bullet in

spawn bullet
set angle of motion angle(bullet.x,bullet.y,cursor.x,cursor.y) and random numbers to cusror coordinates.JohnnySix2012-04-25 13:48:46
Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939

Post » Wed Apr 25, 2012 5:47 pm

I was curious to experiment with this - as I may use something similar for an enemy turret behaviour in a platformer I'm working on.

Ignore the shoddy graphics, just whipped up some placeholder - you get the idea :

Sine Shooter

The method employed in the example is to attach a sine-movement (angle) controlled sprite attached to the cross-hair/mouse position with the magnitude increasing in proportion to the distance the cross-hair is away from the ship.

Download here : SineShooter.capxJohnnySix2012-04-25 17:47:59
Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939

Post » Wed Apr 25, 2012 8:23 pm

Nice Project there Johnny. It sort of adds an extra it of detail to the game. Leaving the bullets shooting straight makes the game look a bit... constructed? While having it a bit waving just helps the game flow. Good job!
B
29
S
4
Posts: 42
Reputation: 2,391


Return to How do I....?

Who is online

Users browsing this forum: MrLOL64 and 21 guests