The Daily Click ::. Forums ::. Klik Coding Help ::. TGF2 projectile not going where it should
 

Post Reply  Post Oekaki 
 

Posted By Message

infinitum3d



Registered
  03/03/2012 22:18:24
Points
  66
13th March, 2012 at 13/03/2012 00:46:53 -

I have an archer shootingan object at my mousecursor. The problem is, it sometimes misses. My hotspot is set to the center of each of my objects. Any idea what could be wrong?


Thanks!

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
13th March, 2012 at 13/03/2012 01:10:41 -

Post your mfa and I'll take a look.

 
n/a

infinitum3d



Registered
  03/03/2012 22:18:24
Points
  66
14th March, 2012 at 14/03/2012 20:24:16 -

So I figured it out. There are only 32 directions the arrow can travel using the Bouncing Ball movement type. (15 if you don't count straight up/straight down or backwards.) Is there any way to increase the number of directions using a different movement type? I can probably calculate actual degrees to get 360 directions (using y=mx+b), but if there is an easier way, I'd love to hear it =

Thanks!

Edited by infinitum3d

 
n/a

Windybeard Games



Registered
  14/04/2005
Points
  219

You've Been Circy'd!VIP MemberCandy Cane
15th March, 2012 at 15/03/2012 01:42:58 -


• Always
→ Set Angle("Player") to ATan2(Y( "Player" )-YMouse, XMouse-X( "Player" ))
→ Set XPos("Bullet") to XPos("Bullet") + (Cos(Angle("Bullet")) * Velocity("Bullet")
→ Set YPos("Bullet") to YPos("Bullet") - (Sin(Angle("Bullet")) * Velocity("Bullet")
→ Set X("Bullet") to XPos("Bullet")
→ Set Y("Bullet") to YPos("Bullet")

• Repeat while left mouse button is pressed
→ Create Bullet at 0,0 from Player
→ Set Angle("Bullet") to Angle("Player")
→ Set XPos("Bullet") to X("Player")
→ Set YPos("Bullet") to Y("Player")

http://cid-b1e7ee094271bbda.skydrive.live.com/self.aspx/Public/shooter2.mfa

got that from a search of articles. (sketchy's post 2009)


 
n/a

infinitum3d



Registered
  03/03/2012 22:18:24
Points
  66
15th March, 2012 at 15/03/2012 12:42:01 -

ATan2 gives a syntax error in TGF2.

 
n/a

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
15th March, 2012 at 15/03/2012 13:27:06 -

Have you seen my archery physics example? Maybe that would help.

http://create-games.com/download.asp?id=7477

 
n/a

Duncan

Thelonious Dunc

Registered
  18/05/2002
Points
  552

VIP Member
15th March, 2012 at 15/03/2012 21:51:40 -

ATan2 was added in build 248 or 249 or something, it works in TGF2:NE. Check version?

 
n/a

infinitum3d



Registered
  03/03/2012 22:18:24
Points
  66
15th March, 2012 at 15/03/2012 23:39:08 -

Yep. Wrong version. Should I run the #253 build or #251?

 
n/a

Duncan

Thelonious Dunc

Registered
  18/05/2002
Points
  552

VIP Member
16th March, 2012 at 16/03/2012 12:57:11 -

I have no idea if there's any benefit to using 251 over 253

 
n/a

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2722
22nd March, 2012 at 22/03/2012 19:06:42 -

Instead of relying on trigonometric functions, just use dy and dx instead

The distance along the horizontal and vertical axis between the archer and the object can be calculated from their respective x and y coordinates, dx = x_object - x_archer and dy= y_object - y_archer.

Those number you get must then be 'normalized' to 1. Example: if the ratio dx/dy is" 50/10, normalize to 1/0.2 meaning 1 pixel to the right and 0.2 pixels up. You can multiply this ratio with the speed of your arrow and you've all the directions you need.

 
Image jenswa.neocities.org

infinitum3d



Registered
  03/03/2012 22:18:24
Points
  66
23rd March, 2012 at 23/03/2012 12:44:17 -

Thanks Jenswa. My original intent was to use the slope intercept equation y = mx + b or more precisely, m = (y2-y1)/(x2-x1).

 
n/a

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2722
23rd March, 2012 at 23/03/2012 21:25:46 -

Your welcome infinitum3d,

last night after posting I continued reading Calculus and read the word slope and I knew that was exactly the word I was looking for. I am a mathematichs teacher in Holland and sometimes I can't find the right English words for these cases, but the explanation mostly rings a bell.

You only need the slope because that will give you right direction, just remember to do the signs the right way.

Scaling the slope (triangle isn't it) should give you full control over the speed.

Happy coding with your archer.

 
Image jenswa.neocities.org
   

Post Reply



 



Advertisement

Worth A Click