wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Tutorials > JASS/AI scripts tutorials
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 05-07-2009, 11:46 AM   #1
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default How to instantly set a unit's facing

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,
Change this into:
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:
Collapse JASS:
// 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.
Attached Files
File Type: mdx dummy.mdx (34.2 KB, 205 views)

Last edited by grim001 : 05-08-2009 at 02:26 AM.
grim001 is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 05-07-2009, 04:26 PM   #2
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 05-08-2009, 02:13 AM   #3
Bobo_The_Kodo
oO
 
Bobo_The_Kodo's Avatar
 
Join Date: Jul 2008
Posts: 580

Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)

Default

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 02:14 AM.
Bobo_The_Kodo is offline   Reply With Quote
Old 05-08-2009, 02:24 AM   #4
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Bobo_The_Kodo
One problem!

The SetUnitLookAt uses terrain height ...

so on a hill this will face wrong pitch

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 12:37 PM.
grim001 is offline   Reply With Quote
Old 05-08-2009, 11:50 AM   #5
MaD[Lion]
MaD Da ViNci
 
MaD[Lion]'s Avatar


Respected User
 
Join Date: Apr 2003
Posts: 1,699

Submissions (10)

MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)

Default

this + infrane's dummy will be awesome
__________________
Current Projects:
MaDOS (outdated)System for object movements & effects - NEW VERSION IS UNDER W.I.P
Cinematic SystemSystem for making better cinematics and with fancy effects
Timing SystemTiming system that simulates the usage of PolledWait just with 0.01 accuracy
MaD[Lion] is offline   Reply With Quote
Old 05-08-2009, 12:37 PM   #6
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

What is infrane's dummy?
grim001 is offline   Reply With Quote
Old 05-08-2009, 01:02 PM   #7
Bobo_The_Kodo
oO
 
Bobo_The_Kodo's Avatar
 
Join Date: Jul 2008
Posts: 580

Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)

Default

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.

Bah, right of course

I don't know what I was thinking ...
Bobo_The_Kodo is offline   Reply With Quote
Old 05-08-2009, 01:43 PM   #8
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Quote:
Originally Posted by grim001
What is infrane's dummy?
It is Anitarf's/Infrane's; the pitch dummy with ~180 animations. See attached.
Attached Files
File Type: mdx PitchDummy.MDX (33.3 KB, 77 views)
__________________

Last edited by Rising_Dusk : 05-08-2009 at 01:43 PM.
Rising_Dusk is offline   Reply With Quote
Old 05-08-2009, 02:03 PM   #9
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

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:
Originally Posted by grim001
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.

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.
grim001 is offline   Reply With Quote
Old 05-08-2009, 02:11 PM   #10
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 05-09-2009, 03:54 AM   #11
Bobo_The_Kodo
oO
 
Bobo_The_Kodo's Avatar
 
Join Date: Jul 2008
Posts: 580

Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)

Default

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.

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 12:38 AM.
Bobo_The_Kodo is offline   Reply With Quote
Old 05-09-2009, 07:35 AM   #12
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

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.
Attached Files
File Type: w3x DummyTest.w3x (24.4 KB, 89 views)

Last edited by grim001 : 05-09-2009 at 08:56 AM.
grim001 is offline   Reply With Quote
Old 05-09-2009, 10:49 AM   #13
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,887

Submissions (4)

Toadcop is just really nice (295)Toadcop is just really nice (295)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

Quote:
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.
lol. i wrote this long ago... and "no one" belived me... especially person called Vexorain <_<

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:
// 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
it takes radians or angles ? (imagine it's not SO obvious especialy for users...) looks like radians.

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)
__________________
Toadcop is offline   Reply With Quote
Old 05-09-2009, 12:32 PM   #14
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Toadcop
btw post what the original idea is by Litany...(afaik) at least i readed this at least ~1 year ago or maybe even earlier.
Well I'm not claiming I invented the idea. But no one has used it for a long time and I'm not sure if anyone ever got it working usefully.

Quote:
Originally Posted by Toadcop
imo for alot objects it may cause performance lose. (wc3 need to rotate model every frame)
It has no effect on performance that I can notice. I've tested this with a lot of bullets at once in my physics engine.
grim001 is offline   Reply With Quote
Old 05-09-2009, 04:18 PM   #15
Bobo_The_Kodo
oO
 
Bobo_The_Kodo's Avatar
 
Join Date: Jul 2008
Posts: 580

Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)

Default

Quote:
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.
I disagree.

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 12:39 AM.
Bobo_The_Kodo is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 03:07 AM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services