Posts | ||
---|---|---|
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:
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 | ||
Sep 8 2020 Anchor | ||
*** You need two variables: - "direction" is actually weapon_direction and 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} /*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 |
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.