HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Physics give me the deer in headlights look

06-23-2008, 07:00 PM#1
Eyestrain92
Alright. I've been around since TFT came out, and I've always tinkered around with the WE and only lately am I getting a bit of popularity for one of my projects, The Lazy War. However, I've decided on going down a different path. I want to create two different maps, but since the second one still gives me a headache thinking about the work required, I need help starting the first one.

Like the person who posted sometime ago, I need to develop a physics system for a map called Catapults. I don't really care about flight, but I need projectiles to explode and knockback enemies, send large shrapnel fragments about, knock around enemies when not directly contacted them, etc. Very specific crud I'll ask about later.

Here's the trouble. I see a lot of JASS around this board, but it's always absolutely confounded me. Anyone who tries explaining it to me thus far has just used the condescending "I'll explain it, but only in a way someone who already knows it could understand, and lord it over them with the confusing vocabulary they know nothing of."

For starters, I just want to know how you would go about setting off an explosion which would knock someone around. If this goes answered, I'll ask then next step, and the next, until this problem is resolved, and if I'm allowed to.

Thanks
06-23-2008, 07:22 PM#2
Anitarf
Quote:
Originally Posted by Eyestrain92
Here's the trouble. I see a lot of JASS around this board, but it's always absolutely confounded me. Anyone who tries explaining it to me thus far has just used the condescending "I'll explain it, but only in a way someone who already knows it could understand, and lord it over them with the confusing vocabulary they know nothing of."
I'm sorry if that's how you feel, but seriously, physics isn't the easiest thing to do, and the reason people explain it while assuming you already know something about it is because if they assumed you know nothing about it, they wouldn't even be trying to explain it. Unless you have at least a basic knowledge (or, better yet, understanding) of both Jass (preferably vJass) and vectors, you can't really expect to be capable of coding simulations of newtonian physics with just a quick explanation from a random forumgoer.

Quote:
For starters, I just want to know how you would go about setting off an explosion which would knock someone around. If this goes answered, I'll ask then next step, and the next, until this problem is resolved, and if I'm allowed to.
If you want specific implementation explanations, you need to be more specific with your questions. "Knocking someone around" can mean many things in terms of code. The most basic implementation would be sliding knockback with constant speed over a fixed duration, all you need for this is a unit array with all the units being pushed back with speed, direction and remaining slide time values stored in parallel arrays and a periodic timer moving all units in the array by small increments many times per second. You could replace parallel arrays with a single array of structs if you're using vJass, also it's usually a faster implementation to replace speed and direction with x and y speed.
06-23-2008, 07:27 PM#3
Eyestrain92
You hit the nail on the head with the second response, but you lost me at "You could replace parallel arrays with a single array of structs if you're using vJass, also it's usually a faster implementation to replace speed and direction with x and y speed."

I'm assuming I could use a buff to add the units to these arrays. I want direction to be the angle the unit was in comparison to the explosion, like if it was to the absolute north of the explosion theoretically, it would move north. I want it all to be relative to a certain value, maybe percentage of HP, lower it gets, the more it slides, accounting for both the speed and time. Unless the time can't be altered using a comparison to the unit's HP...

If I knew more I'd want to make the unit slow down...

There's a way to remove collisions while a unit's under this effect right? Say I want him to bump and bounce or remain sliding into a tree until the effect is done, but if I want him to slide off a cliff and into a crevice I can remove his collisions when he hits the edge (marked by a rect,) and the unit has the sliding buff?

p.s.
Regarding arrays, how do I set the affected units all as the array value? I mean, do I have to do a unit group, and for every unit within range of casting unit, add picked unit to array [current array value + 1] or something along those lines?
06-23-2008, 09:18 PM#4
Anitarf
Quote:
Originally Posted by Eyestrain92
You hit the nail on the head with the second response, but you lost me at "You could replace parallel arrays with a single array of structs if you're using vJass, also it's usually a faster implementation to replace speed and direction with x and y speed."
The first part of that only matters if you're familiar with/intend to use vJass.
The second part means that you can translate the speed and direction into x speed and y speed (x speed = speed * cos(direction)) and then store those values, so you don't need to calculate them every time you move the unit.

Quote:
I'm assuming I could use a buff to add the units to these arrays. I want direction to be the angle the unit was in comparison to the explosion, like if it was to the absolute north of the explosion theoretically, it would move north. I want it all to be relative to a certain value, maybe percentage of HP, lower it gets, the more it slides, accounting for both the speed and time. Unless the time can't be altered using a comparison to the unit's HP...
You don't need buffs and anything can be customized provided your system is general enough, time, speed, anything.

Quote:
If I knew more I'd want to make the unit slow down...
With a constant friction force that's not particularly difficult to do, once you calculate the distance you want the unit to travel, you can easily calculate the starting speed (starting speed = squareroot(2 * distance * decceleration)). You can also just pick a speed and let it slide however far it gets.

Quote:
There's a way to remove collisions while a unit's under this effect right? Say I want him to bump and bounce or remain sliding into a tree until the effect is done, but if I want him to slide off a cliff and into a crevice I can remove his collisions when he hits the edge (marked by a rect,) and the unit has the sliding buff?
If you move the unit with functions SetUnitX and SetUnitY it will ignore collision, if you use SetUnitPosition it won't.

Quote:
p.s.
Regarding arrays, how do I set the affected units all as the array value? I mean, do I have to do a unit group, and for every unit within range of casting unit, add picked unit to array [current array value + 1] or something along those lines?
You add the unit to the array when it begins sliding in your explosion trigger and take it out when it's time runs out/it reaches 0 speed.

Collapse JASS:
//adding a unit to the array
    //"unit" is the unit that is being pushed
    set slidingUnit[numberOfSlidingUnits] = unit //add the unit at the end of the array
    set slidingSpeed[numberOfSlidingUnits] = ...
    ...
    set numberOfSlidingUnits=numberOfSlidingUnits+1
Collapse JASS:
//removing a unit from the array
    //"int" is the array index of the unit being removed from sliding units
    set numberOfSlidingUnits=numberOfSlidingUnits-1
    set slidingUnit[int] = slidingUnit[numberOfSlidingUnits] //use the unit at the end of the array to overwrite the unit being removed
    set slidingSpeed[int] = slidingSpeed[numberOfSlidingUnits]
    ...
06-23-2008, 10:06 PM#5
Eyestrain92
Ahh. It's becoming clearer and clearer. I mentioned the buff to link the trigger to the explosion at the end. Hmmm...

Alright, so the following variables I'll need are a unit variable, a integer variable, and another integer variable, or a real?

I use the move unit instantly trigger, and use the offsets? Now I'm confused again, this time on the actual moving trigger >_>
06-23-2008, 10:30 PM#6
Anitarf
You have the sliding speed, defined in distance units per second, let's say 1000. Then you have your timer period, let's say 0.02 seconds (that makes it run 50 times per second, which should look fairly smooth). The distance the unit travels on each timer tick is then 1000*0.02=20 distance units.

You move it with something like this:
Collapse JASS:
    local integer i=0
    loop
        exitwhen i>=numberOfSlidingUnits
        call SetUnitX(slidingUnit[i], GetUnitX(slidingUnit[i])+slidingSpeed[i]*timerPeriod*Cos(slidingDirection[i]))
        call SetUnitY(slidingUnit[i], GetUnitY(slidingUnit[i])+slidingSpeed[i]*timerPeriod*Sin(slidingDirection[i]))
        set slidingTime[i]=slidingTime[i]-timerPeriod
        if slidingTime[i]<=0 then
            set numberOfSlidingUnits=numberOfSlidingUnits-1
            set slidingUnit[i] = slidingUnit[numberOfSlidingUnits]
            set slidingSpeed[i] = slidingSpeed[numberOfSlidingUnits]
            set slidingDirection[i] = slidingDirection[numberOfSlidingUnits]
            set slidingTime[i] = slidingTime[numberOfSlidingUnits]
        else
            set i=i+1
        endif
    endloop
Of course, you could do a lot of those calculations ahead of time to make it run faster, for example you could have x speed and y speed values stored instead of speed and direction and simply add those to the unit's current position when moving it to the new position.
06-24-2008, 04:45 AM#7
darkwulfv
If you're looking to make a knockback system...
Coding an efficient knockback is an excellent step-by-step tutorial. It does use vJASS, but in a way that you can follow along and not worry about not knowing vJASS.
01-10-2009, 08:50 PM#8
Eyestrain92
I think I'm going to roll with anitarf's ideas.. I'm starting to use Jass, have vJass... so what variables do I need exactly? speed array time array unit array and direction array, units and reals right?
01-10-2009, 09:48 PM#9
Bobo_The_Kodo
If you want to have deceleration, then you would need arrays for:
Unit / Deceleration and xVelocity / yVelocity or velocity / direction

Yes, it would be unit / real arrays