Staredit Network > Forums > SC2 Assistance > Topic: Missile deflection system
Missile deflection system
Mar 23 2012, 10:30 pm
By: luzz  

Mar 23 2012, 10:30 pm luzz Post #1



Im trying to figure out how to make units bounce off of a wall or walk zOne when they hit it. The unit should bounce or reflect off in a near perfect way meaning that if they hit a 90 degree wall facing 60 degrees, they will bounce off and be facing 300 degrees after the impact.

I have looked at multiple sites and each of they say to use 3 points in the terrain to make a triangle on the terrain wall, then find the normal of that triangle.

I'm sure this works but
1. I don't know how to find these points on the wall
2. I don't know how to find the normal/ cross section of a triangle
3. I don't think this method would work if there is no wall to bounce off of.

I hope I was explanatory enough for what I want done. If anyone needs more information on what I want, just ask me for it.

Post has been edited 1 time(s), last time on Mar 23 2012, 10:38 pm by luzz.



None.

Apr 2 2012, 7:33 pm luzz Post #2



Bump, anyone know?



None.

Apr 2 2012, 9:51 pm Roy Post #3

An artist's depiction of an Extended Unit Death

Sorry, I usually jump on these questions immediately, but I've been vacationing.

1) Using the Points layer, you can place your own points. You should need a pair of points for every straight line of the wall (you could reuse corner points, obviously).
2) Ideally, you just want to calculate the perpendicular vector for a line.
3) Of course it will work; you're not actually bouncing off "walls" but the lines created from the points you place. Therefore, you can make them bounce off of virtually anything (even moving walls).

I don't even know how you'd get a diagonal or triangular shape as a region, though, as the only available options are circles and rectangles locked perpendicularly to the x-axis and y-axis. The only thing I've thought of thus far is creating an array of points to cover the wall, but that seems like a huge pain.




Apr 2 2012, 11:06 pm luzz Post #4



Ok... I understand how this would work, I need to place a point on every corner of a terrain wall? I can see some problems here tho, what if the doodad/ wall is circular? And how would I get these points? If I search for the nearest points, I may get the incorrect points and have an incorrect bounce angle. :/



None.

Apr 9 2012, 3:50 am Roy Post #5

An artist's depiction of an Extended Unit Death

Alright, so after a bit of tinkering, I've decided the best course of action to detect collision with a wall would be to check if a point is along the slope between two other points.

To calculate the angle at which something should bounce off of from the wall, I've come up with the formula:
w - (w - o)

Where "w" is the angle of your wall, and "o" is the angle of the direction your unit is moving. This seems to work well for the purposes of your scenario.

I've attached a sample map with a custom function to detect if a point is along the slop between two other points, as that was the main crux of difficulty for me. You can play around with the numbers if you'd like, as the system certainly isn't perfect. You can also ignore the triggers in the "Sliding Stuff" folder, because that is just the system to slide the Marine around and has nothing to do with bouncing.

Attachments:
Bounce.SC2Map
Hits: 4 Size: 14.58kb




Apr 13 2012, 12:58 am luzz Post #6



This is far better than anything I could have done =) but it still doesnt work perfectly D=

This is however a great way to make the bouncing system without the use of terrain walls and such. I have seen multiple maps with a perfect bouncing system. Like Magecraft, and Runling Run. But no matter how hard i try i cant recreate how well they have done it... I may end up having to do it the way magecraft did it and create my own physics system, I don't want to do that though, its too much work for the simple problem of finding the normal of a wall...

I found a sketchy, glitchy way to do it, not as good as yours Roy, but it still works xD

When the unit runs into a wall do the following

1. Check at 45 degree intervals (I used a for each real loop with the integral set to 45) for unpathable terrain
2. Set a variable that corresponds with that point true or false depending on if it was pathable or not
3. Find wall normal using the points that are pathable

The unit sometimes glitches when it hits a corner of a wall, because there are too many points set to true, so it starts to face in multiple directions very fast and doesnt actually go anywhere...

For some reason as well, the unit will also get stuck in the wall (For no apparent reason, I honestly have no idea how it happens) :(



None.

Apr 13 2012, 1:08 am Biophysicist Post #7



Quote
w - (w - o)
I don't mean to be annoying, but I doubt that's what you meant, because that would simplify to just o. >.>



None.

Apr 13 2012, 1:31 am luzz Post #8



-o actually I think xD but it works



None.

Apr 14 2012, 5:08 am Roy Post #9

An artist's depiction of an Extended Unit Death

Quote from Biophysicist
Quote
w - (w - o)
I don't mean to be annoying, but I doubt that's what you meant, because that would simplify to just o. >.>
You're right; that was a typo, and I thank you for correcting me. What I actually used was:
w - (o - w)

Which you can actually simplify to be:
2w - o


Quote from luzz
When the unit runs into a wall do the following

1. Check at 45 degree intervals (I used a for each real loop with the integral set to 45) for unpathable terrain
2. Set a variable that corresponds with that point true or false depending on if it was pathable or not
3. Find wall normal using the points that are pathable
If you're going to brute-force it, start at some arbitrary angle like 0 and check if it's pathable. Then keep checking each angle until you get an angle that doesn't match the result of the first angle, and mark the point of the angle as the first of the two angle points for the wall. Then continue until you reach an angle that matches the result of the first angle, and mark the point of the angle as the second of the two angle point for the wall. Then take the angle of the two marked points to get the angle of the wall, and then use the formula to calculate how the object should bounce off that angle.

Quote from luzz
The unit sometimes glitches when it hits a corner of a wall, because there are too many points set to true, so it starts to face in multiple directions very fast and doesnt actually go anywhere...
I had a similar issue when building my system, which is why I put all the checks into an Else-If block, so it wouldn't execute the angle manipulation more than once.




Apr 14 2012, 1:45 pm luzz Post #10



Yes, the 45 degree angle delio was just something my primitive mind came of with, your way is much much better. I'm going to tinker around with it some more.

Found a problem, if the marine heads directly at a corner, he will go right through it. Im going to add another else if that asks if the bouncer is near any of the points, and if he is, turn him around, that should fix the problem.

Tyvm by the way roy!! U rock!! :D



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[09:38 pm]
NudeRaider -- Ultraviolet
Ultraviolet shouted: NudeRaider sing it brother
trust me, you don't wanna hear that. I defer that to the pros.
[07:56 pm]
Ultraviolet -- NudeRaider
NudeRaider shouted: "War nie wirklich weg" 🎵
sing it brother
[2024-4-27. : 6:24 pm]
NudeRaider -- "War nie wirklich weg" 🎵
[2024-4-27. : 3:33 pm]
O)FaRTy1billion[MM] -- o sen is back
[2024-4-27. : 1:53 am]
Ultraviolet -- :lol:
[2024-4-26. : 6:51 pm]
Vrael -- It is, and I could definitely use a company with a commitment to flexibility, quality, and customer satisfaction to provide effective solutions to dampness and humidity in my urban environment.
[2024-4-26. : 6:50 pm]
NudeRaider -- Vrael
Vrael shouted: Idk, I was looking more for a dehumidifer company which maybe stands out as a beacon of relief amidst damp and unpredictable climates of bustling metropolises. Not sure Amazon qualifies
sounds like moisture control is often a pressing concern in your city
[2024-4-26. : 6:50 pm]
Vrael -- Maybe here on the StarEdit Network I could look through the Forums for some Introductions to people who care about the Topics of Dehumidifiers and Carpet Cleaning?
[2024-4-26. : 6:49 pm]
Vrael -- Perhaps even here I on the StarEdit Network I could look for some Introductions.
[2024-4-26. : 6:48 pm]
Vrael -- On this Topic, I could definitely use some Introductions.
Please log in to shout.


Members Online: Oh_Man