Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / 2d math

Author
Message
Levowen
21
Years of Service
User Offline
Joined: 19th Oct 2004
Location:
Posted: 19th Oct 2004 14:20
Hi I'm new to Dark basic and ya I'm stuck on 2d math...

I'm trying to make an auto aiming gun.

and so I went (all psuedo like)

Xvec = Xtarget - Xorigin
Yvec = Ytarget - Yorigin
sqrt(XVec*XVec + Yvec*Yvec)

then broke "tried" to break it down into units, like some 2d math tutorials stated by dividing each component of the vector by the vectors length which is supposed to bring it to 1 unit distances...

unfortunatly... it doesn't... it brings it right to 0

Please help.. any ideas welcome and if you tell me this way is crap and you have a much cooler way of doing it.. I'll believe you
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Oct 2004 08:34
auto aim huh? can't you just point the gun to the coordinates of the target?

"eureka" - Archimedes
mr joe
21
Years of Service
User Offline
Joined: 12th Aug 2004
Location: Edinburger, Scotland. DBC
Posted: 23rd Oct 2004 05:13 Edited at: 23rd Oct 2004 05:14
i think what the tutorials mean is you find a common factor between the two vector components, ie one of the lengths and then divide them both by this. but im not really sure why you need to have single unit distances.

if you need to work out the line of fire it might be easier to use trigonometry rather than vectors, something like:

angle=atan((Ytarget-Yorigin)/(Xtarget-Xorigin))

then for each position you can do something like:

ypos=ypos+sin(angle)*x
xpos=xpos+cos(angle)*x

where x is the distance you want the bullet to move along its line of fire

i hope thats helpful
Bona
21
Years of Service
User Offline
Joined: 22nd Oct 2004
Location:
Posted: 23rd Oct 2004 06:22
There is something with the last post. I think it will work. But can you plz tell me how to get the x value.

The one and only Bona

Login to post a reply

Server time is: 2026-06-11 17:33:56
Your offset time is: 2026-06-11 17:33:56