HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Reverse Unit Facing and Travelling Direction

06-01-2006, 07:56 AM#1
James59281
Hi! Below i've posted my code for making a bullet move. (It's pretty basic, but bear with me).
An essential part of the code is that if the bullet comes too close to a unit, it will deal damage to the unit. BUT, if the unit has a 'bullet deflector' of which there are two variants, i want the bullet to fly back off in the opposite direction.
Since i'm moving the bullet in the direction it's facing, i figured i could do it by just turning the bullet around, and the trigger would handle the rest.
But i have a problem - when the bullet gets close to a unit with a bullet deflector, it doesn't reflect but travels in a weird circular path and flies off in a weird direction.

Some notes:
The mana of the bullet unit is used to keep track of how far it has travelled.
PickedUnit and Picked unit are different.

Trigger:
Collapse Events
Time - Every 0.01 seconds of game time

Collapse Actions
Set UnitGroup_A = (Units in (Entire map) matching (((Unit-type of (Matching unit)) Equal to Bullet)
Collapse Unit Group - Pick every unit in UnitGroup_A and do (Actions)
Collapse Loop - Actions
Set PickedUnit = (Picked unit)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Collapse Then - Actions
Unit - Move (Picked unit) instantly to ((Position of (Picked unit)) offset by 8.00 towards (Facing of (Picked unit)) degrees)
Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) + 8.00)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Mana of (Picked unit)) Greater than or equal to 2000.00
Collapse Then - Actions
Unit - Kill (Picked unit)
Else - Actions
Set UnitGroup_B = (Units within 60.00 of (Position of PickedUnit))
Collapse Unit Group - Pick every unit in UnitGroup_B and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Mana of PickedUnit) Greater than 60.00
((Picked unit) is dead) Equal to False
(PickedUnit is dead) Equal to False
(Level of 100% Evasion for (Picked unit)) Equal to 0
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Picked unit) has an item of type Bullet Deflector 1) Equal to False
((Picked unit) has an item of type Bullet Deflector 2) Equal to False
Collapse Then - Actions
Unit - Cause PickedUnit to damage (Picked unit), dealing 1000000000.00 damage of attack type Normal and damage type Normal
Else - Actions
-------- ****** BULLET DEFLECTION ****** --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
((Picked unit) has an item of type Bullet Deflector 1) Equal to True
((Picked unit) has an item of type Bullet Deflector 2) Equal to True
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Facing of PickedUnit) Less than 180.00
Collapse Then - Actions
Unit - Move PickedUnit instantly to ((Position of PickedUnit) offset by 0.00 towards ((Facing of PickedUnit) + 180.00) degrees), facing ((Facing of PickedUnit) + 180.00) degrees
Collapse Else - Actions
Unit - Move PickedUnit instantly to ((Position of PickedUnit) offset by 0.00 towards ((Facing of PickedUnit) - 180.00) degrees), facing ((Facing of PickedUnit) - 180.00) degrees
Else - Actions
Else - Actions
Custom script: call DestroyGroup (udg_UnitGroup_B)
Else - Actions
Custom script: call DestroyGroup (udg_UnitGroup_A)


The bit at the end is because i wasn't sure if the world editor would know that
200 degrees + 180 degrees = same angle as 20 degrees
Is this the case? Or should i forget about this messy bit and just say facing angle = facing angle + 180 and let the world editor sort it out?


(So there's two questions in one post.)
06-01-2006, 08:39 AM#2
PipeDream
yes, the symmetry will be obeyed 99.9%. there might be a difficulty with numerical stability if the angle grows too large(10^7 degrees or so), however, I believe the internal representation of facing angle forces it to -180 to 180 or 0 to 360 so that won't be a problem.
06-01-2006, 08:56 AM#3
James59281
Yay! So i got rid of the angle checking and just put angle = angle + 180 and it's working exactly the same as before, so that's good.
But it's also bad because it wasn't working properly in the first place! lol.

So, back to my original question, can anyone see a problem in my code? I'm specifically looking for any reason why the bullet should not simply turn around (it does sort of a U-turn rather than just reversing direction.)
06-01-2006, 11:47 AM#4
blu_da_noob
Because there is a limit to how fast units will change their facing angle, no matter what speed you tell them to do it at (ie. over 0 seconds doesn't make it instant).

The best you can do is create a new unit of exactly the same type facing the new angle you need (and remove the old on ofcourse).
06-01-2006, 12:18 PM#5
PerfectlyInsane
Quote:
Originally Posted by blu_da_noob
Because there is a limit to how fast units will change their facing angle, no matter what speed you tell them to do it at (ie. over 0 seconds doesn't make it instant).

The best you can do is create a new unit of exactly the same type facing the new angle you need (and remove the old on ofcourse).


Isnt there a spell like Terror ? or fear spell .... make it only target wards... and make the missles wards.


Just add a condition if the missle is within a certain distance of the the casting unit the above triggers will not affect it. besids I dont think movement triggers can over-ride that spell