![]() |
#1 |
requires vJass
Code Moderator
|
![]() So, you want to recycle dummy units for your projectile system, but you've run into a problem that has plagued mapmakers forever. You can't instantly set the facing of a unit. Turns out there is a way to do it, but it will take a little work, and it is limited. But it's enough to successfully implement dummy recycling for most projectiles.
First of all, an edit to the dummy.mdx file is required. I have attached the edited dummy.mdx to this post, so you don't have to follow these steps, but this is how it was changed. 1.) Download vexorian's xe system. 2.) Export the dummy.mdx model from the map. 3.) Use an mdx <-> mdl converter such as this one to convert it into an mdl file. 4.) Edit the file at the following point: Code:
Helper "Bone_Root" { ObjectId 0, Code:
Helper "Bone_Head" { ObjectId 0, 5.) Save the changes and convert it back from mdl to mdx. OK, so now you know the steps that were taken to change the dummy model. If you downloaded the attached dummy model, you should follow the directions starting from here: 1.) Import the new dummy.mdx into your map. 2.) Create a dummy unit. Change "Art - Animation - Blend Time (seconds)" to 0 seconds. 3.) Change the dummy unit's model to the dummy.mdx file. 4.) Copy the following functions into your map: ![]() // To make the dummy face a 2 dimensional orientation instantly: function SetDummyFacing takes unit u, real angle returns nothing call SetUnitLookAt(u, "Bone_Head", u, Cos(angle)*1000000., Sin(angle)*1000000., 0.) endfunction // To make the dummy face a 3 dimensional orientation instantly: function SetDummyOrientation takes unit u, real x, real y, real z returns nothing call SetUnitLookAt(u, "Bone_Head", u, x*1000000., y*1000000., z*1000000.) endfunction //To make the dummy always face a particular unit, for homing missiles: function SetDummyHomingTarget takes unit u, unit target returns nothing call SetUnitLookAt(u, "Bone_Head", target, 0., 0., 0.) endfunction 5.) Create the dummy unit in game and attach your projectile's model to it. 6.) Call one of the above functions on your projectile. You should only do this once per time the projectile is recycled. If you try to call these functions continuously, it won't animate correctly. You can't use this instant facing stuff in conjunction with the dummy model's pitch animations. The dummy will be pitched at an angle that matches its real facing, not the fake facing we have given it by adjusting the head bone. So, this trick is only useful for projectiles that face one angle or follow one unit and never change from that until they get recycled. It is possible to change the angle or target while the projectile is still being used, but most likely the unit will flicker to face the wrong direction for an instant if you do so. By only calling these functions as the unit gets recycled, that flicker can be concealed from the player. Why do I want to recycle projectiles anyway? Every time you create a new unit and destroy it, WC3's memory use goes up and doesn't seem to come back down. It causes performance degradation over time even if you don't leak. Creating units is just about the slowest thing possible in WC3, too. If you try to make a machine gun that fires 20 bullets per second by creating dummy units, you will lag. With unit recycling, I have made a machine gun that can fire over 200 bullets per second before the framerate starts to dip (and I am sure it was because of the 200 bullets traveling, not because of creating 200 bullets). And if 200 bullets per second sounds excessive, just imagine that as 10 players each firing the 20 bullet per second machine guns. Whether you notice any improvement in a particular map is going to depend on how many projectiles it creates over time and what interval they're created at. I highly recommend unit recycling for any shooter-type map that has guns firing at a high frequency. For other types of games, unit recycling should be optional. To be added: A guide on how to actually implement projectile recycling. A test map demonstrating everything. Last edited by grim001 : 05-08-2009 at 03:26 AM. |
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#2 |
Obscurity, the Art
|
![]() Fix some of your bbcode errors (you have a bold misuse in there) and then maybe add a testmap or something. Also, since you talk so much about recycling the dummies, you will want to explain just how to 'recycle' the dummies faced in this manner so that they can be reused later.
__________________I read it over and like it on the whole, though, so if you do those things I'll go ahead and approve this. |
![]() |
![]() |
![]() |
#3 |
oO
Join Date: Jul 2008
Posts: 580
![]() ![]() ![]() ![]() |
![]() One problem!
The SetUnitLookAt uses terrain height ... so on a hill this will face wrong pitch edit: more complicated than this to get it to work usefullly Last edited by Bobo_The_Kodo : 05-08-2009 at 03:14 AM. |
![]() |
![]() |
![]() |
#4 | |
requires vJass
Code Moderator
|
![]() Quote:
This is wrong, terrain heights only exist in a range of several thousand. When you multiply the X and Y coordinates by 1,000,000 each, the incorrectness of the Z orientation would become completely negligible. And that's if what you're saying were true, but double check the function... the unit is looking at itself with an offset, meaning it already has its own Z height factored in. It works fine when I use it in my physics engine. Last edited by grim001 : 05-08-2009 at 01:37 PM. |
|
![]() |
![]() |
![]() |
#5 |
MaD Da ViNci
Respected User
Join Date: Apr 2003
Posts: 1,699
![]() ![]() ![]() ![]() |
![]() this + infrane's dummy will be awesome
__________________ |
![]() |
![]() |
![]() |
#6 |
requires vJass
Code Moderator
|
![]() What is infrane's dummy?
|
![]() |
![]() |
![]() |
#7 | |
oO
Join Date: Jul 2008
Posts: 580
![]() ![]() ![]() ![]() |
![]() Quote:
Bah, right of course I don't know what I was thinking ... |
|
![]() |
![]() |
![]() |
#8 | |
Obscurity, the Art
|
![]() NOTE: You have been redirected in order for our attachments to be made available to you. This will only last two minutes; these measures where taken to avoid hotlinking and bandwidth theft. To avoid these restrictions Log in or Register Quote:
Last edited by Rising_Dusk : 05-08-2009 at 02:43 PM. |
|
![]() |
![]() |
![]() |
#9 | |
requires vJass
Code Moderator
|
![]() Is there actually any difference between that and the xe dummy? I can't really see one after looking at it.
MadLion, sorry to burst your bubble if you thought you could get 360 degree rotations from combining this with the pitch animations: Quote:
Once I make a demo map for this tutorial I'm going to check out if there are any more possibilities when you make the dummy face a hidden unit, maybe we can still get 360 degree rotations working smoothly, don't count on it though. |
|
![]() |
![]() |
![]() |
#10 |
Obscurity, the Art
|
![]() Vex made the xe dummy long after Inf/Ani made the pitch dummy, so some older users still use Inf/Ani's just because there's really no need to update to xe's as it is the same.
__________________ |
![]() |
![]() |
![]() |
#11 | |
oO
Join Date: Jul 2008
Posts: 580
![]() ![]() ![]() ![]() |
![]() Quote:
Rawr, I did these tests.. SetUnitLookAt only updates approximately every 0.2 seconds.. So its like dusk's choppy knockback system x4... (and also you can't do pitch properly with this (unless you can somehow do negative fly heights at runtime?)) edit: it also takes a long time to get the dummy unit set to proper spot -> need to put on edge of map if you want projectile dummies not to glitch edit2: attached testmap (tx,ty on setdummyfacing should be simplified (im overcomplicating by far) ), so you can see the choppyness! edit3: i probably will still use the way attached in testmap for my own spells, but not have a curving projectile or like that, just to change direction at a chop Last edited by Bobo_The_Kodo : 05-10-2009 at 01:38 AM. |
|
![]() |
![]() |
![]() |
#12 |
requires vJass
Code Moderator
|
![]() What's with all of the unnecessary and ugly code in that test map?
It's not SetUnitLookAt that won't update, it's your SetDummyFacing function that's incorrect. It is deliberately designed to only pick one of 8 angles rather than rotating in a complete circle. Try using my function instead of yours and you will see that the facing angle updates instantly, but flickers to an incorrect direction each time it's set. If you want a unit to achieve perfectly smooth rotation you need to make it follow another unit, I included a test map to demonstrate. If you want to manipulate a unit's pitch, there are four ways that work: 1.) Make your projectile face any 3 dimensional orientation you want when it spawns, and leave it that way until the projectile gets recycled. 2.) Make your projectile face a homing target, it will naturally pitch to face it and it will animate smoothly. 3.) If you want to set pitch to an arbitrary value, you need to make the dummy unit follow another invisible unit. But you can't pitch straight down unless the projectile is in the air, otherwise the invisible unit can't fit underneath it. 4.) Or just use the pitch animations of the dummy unit, but you can't combine these with any sort of instant facing. If you want instant facing too you would need to create a new unit. Last edited by grim001 : 05-09-2009 at 09:56 AM. |
![]() |
![]() |
![]() |
#13 | ||
BuranX
|
![]() Quote:
btw post what the original idea is by Litany... (afaik) at least i readed this at least ~1 year ago or maybe even earlier. Quote:
imo for alot objects it may cause performance lose. (wc3 need to rotate model every frame) but ofc i don't know how exactly and much it will degrade it. (cause the initial purporse of this are cinematics) |
||
![]() |
![]() |
![]() |
#14 | ||
requires vJass
Code Moderator
|
![]() Quote:
Quote:
|
||
![]() |
![]() |
![]() |
#15 | |
oO
Join Date: Jul 2008
Posts: 580
![]() ![]() ![]() ![]() |
![]() Quote:
I just set bounds so that it thinks map is really small, and guess what? It worked fine It appears its based on distance or something...? (yes, view 3rd testmap) (but yes I need to clean code for SetDummyFacing) Edit: And a second testmap, with it as a constant distance toward the angle... the problem with this is you need to call UpdateDummyFacing( unit ) whenever you move dummy Also, I need to find out how to set unit fly height negative, I'll ask Litany Edit: And a third testmap, proving it updates at a lower frequency from higher distance (blizzard probably thought the unit would move smaller % of angle change, = distance moved / distance between units..) Last edited by Bobo_The_Kodo : 05-10-2009 at 01:39 AM. |
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|