The Daily Click ::. Forums ::. Klik Coding Help ::. How? Pinpoint accuracy when shooting towards crosshairs
 

Post Reply  Post Oekaki 
 

Posted By Message

Marcello64



Registered
  16/05/2007
Points
  144
27th February, 2009 at 17:29:48 -

So I have a character on screen controlled with arrow keys, and a mouse controlled crosshair.

Current Event:

Fire 2 is pressed, shoot 'bullet' from 'player' in the direction of 'crosshair' 0'0

the thing is, its not shooting directly at the middle of the crosshair, i have the action/hotspot located in the middle of it, but most of the time it shoots just under the WHOLE crosshair, i need pinpoint accuracy.

Help much appreciated.

 
Sig: I'm not the Marcello from Cellosoft.

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
27th February, 2009 at 17:59:19 -

It's becasue you're using a built-in movement for the bullet. This means the bullet can only travel in one of 32 different directions.

You need to use some simple trigonometry to make the shooting precise. If you search for "360 degree shooting / aiming" I'm sure you'll find heaps of examples, but basically it's like this:

* Fire is pressed
-> create "Bullet"
-> set Alterable Value X("Bullet") to X("Player")
-> set Alterable Value Y("Bullet") to Y("Player")
-> set Alterable Value A("Bullet") to angle between player and crosshair (use the advanced direction extension to find this).

* Always
-> set Alterable Value X("Bullet") to Alterable Value X("Bullet")+(Cos(Alterable Value A("Bullet")) * Bullet_Speed)
-> set Alterable Value Y("Bullet") to Alterable Value Y("Bullet")-(Sin(Alterable Value A("Bullet")) * Bullet_Speed)
-> set X("Bullet") to set Alterable Value X("Bullet")
-> set Y("Bullet") to set Alterable Value Y("Bullet")

 
n/a
   

Post Reply



 



Advertisement

Worth A Click