The Daily Click ::. Forums ::. Klik Coding Help ::. inaccurate passing/shooting
 

Post Reply  Post Oekaki 
 

Posted By Message

Gregorian Chan



Registered
  12/05/2006
Points
  7
6th July, 2007 at 18:13:06 -

Hi, I have two objects in my frame. When the user presses fire object (a) will shoot another object towards object (b).
My problem is I want the accuracy of the shot to be dependant on an accuracy gauge. So say if the gauge is equal to -30 then the bullet should head -30 pixels left of object b. +30 then it should head 30 pixels right of object (b)
So I can't just say for the bullet to head towards -30 of y pos of abject (b) cause that would be assuming that object (a) and (b) are always at the same y coordinate.
and using the above calcutation for example when the objects are both on the same x coord wouldnt work because the bullet would still go toward object (b).
In other words the bullet should aim at right angles of object (b) relative to (a) and the distance is dependant on the gauge. I hope I explained it properly.
Any ideas?

 
n/a

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
7th July, 2007 at 10:16:23 -

Cheapest way would be to have an invisible object located (to use your example) 30px from the target, and aim at that. Actually, it's not all that cheap, because it still needs to be positioned at an angle relative to the angle between the shooter and target.

Something like:
invisibletarget: set X position to X("target")+cos([angle between shooter and target]+90)* [accuracy]
invisibletarget: set Y position to Y("target")+sin([angle between shooter and target]+90)* [accuracy]

That's just off the top of my head, but hopefully the result should be something like:

S
.
.
.
T <-acc-> I

Where (I)nvisibletarget is [(acc)uracy] distance from (T)arget, at a 90 degree offset from the angle between (S)hooter and t(T)arget.

The point of this is that it should work whether you're using a custom engine or the built-in 'shoot' action, but note the latter option only has 32 degrees of precision anyway, so won't be pixel-perfect.

If you are using a custom 360-degree engine you could do this purely mathematically, by adapting the above formula in your aiming code rather than having an actual invisibletarget object.

 
n/a

Gregorian Chan



Registered
  12/05/2006
Points
  7
7th July, 2007 at 23:59:12 -

Thanks Heaps Radix
The formula worked except The X position line had to be -90 not +90. It was aiming the X on the wrong side of the target thats all.


 
n/a
   

Post Reply



 



Advertisement

Worth A Click