• Register
Forum Thread
  Posts  
How to deal with 0-39 (Forums : Coding & Scripting : How to deal with 0-39) Locked
Thread Options
Jul 26 2020 Anchor

Hi MODDB.

I currently have a problem that i can't wrap my head around.

I have a vehicle direction with an output of 0-359 degrees and I wan't other stuff to keep a certain direction (like a weapon system on the roof).

The basic solution would be something like this:

if (weapon_direction < vehicle_direction) 
  {
  //Turn weapon system right
	}

else
  {
  //Turn weapon system left
	}

BUT, the problem occurs when the direction crosses the "0" point resulting in the weapon system going the long way around because it doesn't know that the shortest way from ex 350 degrees to 5 degrees would be to cross that 0-point.


Do you have any ideas of how to do this?

/Morten

Jul 27 2020 Anchor
HITASIAQI wrote:

I have a vehicle direction with an output of 0-359 degrees and I wan't other stuff to keep a certain direction (like a weapon system on the roof). Kodi nox

Sorry, but the links (kodi + nox) doesn't go anywhere?

Sep 8 2020 Anchor

***
Hey man globey.dk
I just saw your post, and after a few moments of fast thinking, emergency variant raised.

You need two variables:
direction and point_direction

- "direction" is actually weapon_direction and
- "point_direction" is position of enemy object(enemyTarget).
***
in step put this:

vehicle_direction = point_direction(x,y,enemyTarget.x,enemyTarget.y); /* enemyTarget is targeted object */

weapon_direction=direction; /*"direction" is built in engine variable - direction of gun so use it instead of weapon_direction*/

if round(direction)==round(vehicle_direction){/*weapon shooting at enemy and other things*/ exit;}

if direction > 230 and vehicle_direction < 90 {direction+=1;exit}
if direction < 90 and vehicle_direction > 250 {direction-=1;exit}
if direction > vehicle_direction {direction-=1;exit}
if direction < vehicle_direction {direction+=1;exit}


/*it`s not so precise but will do the job.

Original variant include sine of x, cosine of x and others formulas*/

Edited by: Bazlik_Commander

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.