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! / Angle Trajectory

Author
Message
kkun
14
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 6th Mar 2010 04:24
Hi there guys,
i've been trying to find a way, or thinkning but its not coming to me.

What i want to do is something like scorched earth with the tank angles when you choose the direction in which to shoot.

What i'm wondering is how do i draw the angle for it to go automatically from lets say angle 45 to angle 315 automatically and then go back in the oppositie direction and then when you stop it at a certain angle it will shoot.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 6th Mar 2010 15:37 Edited at: 6th Mar 2010 15:38
I think it would be easier to just use a -45 to 45 range, that way SIN and COS will still work, and you can fogoe using wrapvalue or comparing angles.

Maybe something along these lines...

If spacekey()=1
if shooting=0 then shooting=1 : ang#=-45.0
else
if shooting=1 then shooting=2
endif

if shooting=1
inc ang#,0.1
endif

if shooting=2
`Fire bullet
xs#=sin(ang#)
ys#=cos(ang#)
shooting=0
endif


To set the turret left or right, you could just invert ang#, maybe have a multiplier that is either 1.0 or -1.0 depending on which way the tank is facing.


Health, Ammo, and bacon and eggs!
Dia
19
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 9th Mar 2010 12:46 Edited at: 9th Mar 2010 12:59
I could be wrong, but I think kkun means that the gun barrel will oscillate between -45 and 45 degrees from the vertical until the user lets go the fire button, at which time the barrel freezes and the exploding sheep (or projectile of your choice ) can be pushed out in whatever direction that the barrel happens to be facing at the time

in which case a wrapvalue or bounce function to alter the barrel angle every loop would probably be necessary. Something like:



*yes I know this rotates from the center of the 'barrel' but it illustrates the concept

when you want to fire, you can use the sx# and sy# calcs from van B's example, just make sure that you use the barrel object's zangle to calculate the projectile trajectory

This is not the Sig you are looking for....
kkun
14
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 9th Mar 2010 14:50
wow omg, that is exactly what im looking for DIA, thank you so much. Now to mess around with it to get it working for me haha.

VanB : Ive been doing something similar to that but it wasnt working out for me. =\
Dia
19
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 10th Mar 2010 12:29
no worries mate, glad I could help

This is not the Sig you are looking for....

Login to post a reply

Server time is: 2024-04-24 11:49:01
Your offset time is: 2024-04-24 11:49:01