• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Center a shadow on a unit

Status
Not open for further replies.

Cokemonkey11

Code Reviewer
Level 29
Joined
May 9, 2006
Messages
3,522
Does anyone know how to make a shadow have its center at the origin of the unit?

I have a dummy unit that right now is just a shadow (to make an object of changing height easier to recognize with depth perception)

The problem is not everyone has shadows enabled so I'd like to also put a small unit at the center of that shadow.
 
Level 23
Joined
Oct 12, 2008
Messages
1,783
Well its a combination of Shadow Image X/Y and Shadow image Heigth/Width.

AFAIK the greater your Height/Width and hence the size of the shadow is the larger value for shadow imade X/Y you need to make it center.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
The x and y in SetImagePosition(whichImage, x, y, z) are the coordinates of the lower left corner of the image.

If your image size is 64x64 for example

x = GetUnitX(u) + SquareRoot((64/2)^2+(64/2)^2)*Cos(-3*PI/4)
y = GetUnitY(u) + SquareRoot((64/2)^2+(64/2)^2)*Sin(-3*PI/4)

The unit's origin coordinates will be offset towards an angle of 225 degrees (angle from the origin to lower left corner) by half the diameter of the image.

Naturally you should precalculate the SquareRoot((64/2)^2+(64/2)^2)*Cos(-3*PI/4) and SquareRoot((64/2)^2+(64/2)^2)*Sin(-3*PI/4) because they will always be the same. Set them to a variable.
 
Status
Not open for further replies.
Top