- Joined
- Aug 13, 2007
- Messages
- 309
Apparently I can get the height of the terrain with this function:
I want a generator where the higher or lower the point is above 12.0 the less likely it is for a tree to spawn so: 12.0 = 18% chance for a tree to spawn.
It should rapidly fall off as it gets lower and less rapidly for as it gets higher.
I will also stunt the tree growth at higher heights but I believe I know how to do that if I can just figure out how to do the math here probably.
The thing is I don't know how how to do the math behind this in a nice way...
I think I'm trying to do the same thing as like with a cars acceleration or a flamethrowers overheat where it approaches a certain maximum but never quite gets there. It should approach 0% chance of a tree spawning as it gets higher or lower and at different rates.
JASS:
WorldHeight(c_heightMapGround, Point(0.0, 0.0))
I want a generator where the higher or lower the point is above 12.0 the less likely it is for a tree to spawn so: 12.0 = 18% chance for a tree to spawn.
It should rapidly fall off as it gets lower and less rapidly for as it gets higher.
I will also stunt the tree growth at higher heights but I believe I know how to do that if I can just figure out how to do the math here probably.
The thing is I don't know how how to do the math behind this in a nice way...
I think I'm trying to do the same thing as like with a cars acceleration or a flamethrowers overheat where it approaches a certain maximum but never quite gets there. It should approach 0% chance of a tree spawning as it gets higher or lower and at different rates.
I have created a pre-made map with terrain where the height varies and I've basically made myself some cliffs and steep hills and the likes. I want to make it so that units (and other objects such as balls) can slide down the terrain. How do I do this?
I also want to make gravity for my projectiles... I'm not sure how it works though. There are 3 forces right? Velocity, acceleration, and gravity? Is acceleration velocity/time? What is acceleration? How do I get this to work?
This is what DrSuperGood has shown me but I still don't understand :'(
This is what DrSuperGood has shown me but I still don't understand :'(
// how this bloody thing is derived...
za = acceleration at z axis
zv = ʃ za dt = za*t + C
z = ʃ zv dt = (za*t^2)/2 + Ct + D
C = initial speed
D = initial distance
// constants
t = 0.1 // the update period
// int the thing
z = 0 // ground level.
zv = 20 // we are jumping upwards at 20 units a second... in SC2 this guy will be in orbit in no time.
za = -9.8 // we are falling due to gravity which we assume is uniform and not a field that drops with height from ground. -9.8 SC2 units will be 1 damn strong attraction force.
//this is done perodicly
z = z+zv*t+za*t*t/2 // current z + z due to velocity + z due to acceleration
zv = zv+za*t // update current velocity based on acceleration
za = acceleration at z axis
zv = ʃ za dt = za*t + C
z = ʃ zv dt = (za*t^2)/2 + Ct + D
C = initial speed
D = initial distance
// constants
t = 0.1 // the update period
// int the thing
z = 0 // ground level.
zv = 20 // we are jumping upwards at 20 units a second... in SC2 this guy will be in orbit in no time.
za = -9.8 // we are falling due to gravity which we assume is uniform and not a field that drops with height from ground. -9.8 SC2 units will be 1 damn strong attraction force.
//this is done perodicly
z = z+zv*t+za*t*t/2 // current z + z due to velocity + z due to acceleration
zv = zv+za*t // update current velocity based on acceleration
EDIT: Just experimenting myself and with some tips from an old friend I managed to get gravity working! Here's the current form my script takes... now I don't know how to do sliding and bouncing off of terrain though.
JASS:
//---------- Configurable Constants ----------
const fixed c_gravityTimerInterval = 0.1;
const fixed c_gravity = 9.8;
//--------------------------------------------
trigger gt_gravity = TriggerCreate("gt_Gravity_Func");
timer gv_gravityTimer = TimerCreate();
fixed gv_zBoost;
bool gt_Gravity_Func (bool testConds, bool runActions) {
int lv_i = 1;
unit lv_u = UnitGroupUnit(gv_gravityUG, lv_i);
fixed lv_z;
fixed lv_za = (gv_zBoost*c_gravityTimerInterval);
fixed lv_zg = (c_gravity*c_gravityTimerInterval);
while(lv_u != null) {
lv_z = UnitGetHeight(lv_u);
lv_z = lv_z - (c_gravity*c_gravityTimerInterval);
UnitSetHeight(lv_u, lv_z + lv_za - lv_zg, c_gravityTimerInterval);
DebugMsg("Z: " + FixedToString(lv_z, 2));
lv_u = UnitGroupUnit(gv_gravityUG, lv_i);
lv_i += 1;
}
gv_zBoost = gv_zBoost - lv_za;
return true;
}
// Register Physics Timer Event
void gt_Gravity_Init () {
TimerStart(gv_gravityTimer, c_gravityTimerInterval/2, true, c_timeReal);
TriggerAddEventTimer(gt_gravity, gv_gravityTimer);
}
To make them fly I currently just do this each time a unit is given a smart order:
JASS:
gv_zBoost = 30.0;
Last edited: