Any way to have an image rotate and face a unit?

Started by Nicant, December 23, 2015, 04:59:26 PM

Previous topic - Next topic

Nicant

I am trying to make a creeper gun unit that fires on player made units, i have gotten the firing part done, now all i need is to have a way for the barrel to rotate and face the player made units. Any help will be greatly appreciated and be credited.  :)
CW4 hype!!

Grayzzur

Virgil's Alpha Sector map Chimera has gun/barrel code that does that. It's been copied into many maps.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

GameGibu

#2
Trigonometry. Math. Calculus be good too, but ye not necessarily be needin' it fer this here job.

And not to forget, thar be SetImageRotation.

#Self is Self-explanatory
#"main" actually could be anything as long as it matches what you used in SetImage if you used that. If you just used the ingame selection, this does have to be "main", though your whole image will rotate.
#rotationInRadians this is what you calculate with trig, namely atan2.
#I'm assuming that you have successfully detected your target unit.
->TargetUnit
<-TargetUnit CONST_COORDY GetUnitAttribute CurrentX sub ->xDIST
<-TargetUnit CONST_COORDY GetUnitAttribute CurrentY sub ->yDIST
atan2(y2 CurrentY sub x2 CurrentX sub) ->result
SetImageRotation(Self "main" <-result)


Aye, and a good day to ye!
-GameGibu

Yarr...
Bringing you Custom maps since 2971!
☆CRPL Master☆

Nicant

Quote from: GameGibu on January 05, 2016, 02:07:50 AM
Trigonometry. Math. Calculus be good too, but ye not necessarily be needin' it fer this here job.

And not to forget, thar be SetImageRotation.

#Self is Self-explanatory
#"main" actually could be anything as long as it matches what you used in SetImage if you used that. If you just used the ingame selection, this does have to be "main", though your whole image will rotate.
#rotationInRadians this is what you calculate with trig, namely atan2.
#I'm assuming that you have successfully detected your target unit.
->TargetUnit
<-TargetUnit CONST_COORDY GetUnitAttribute CurrentX sub ->xDIST
<-TargetUnit CONST_COORDY GetUnitAttribute CurrentY sub ->yDIST
atan2(y2 CurrentY sub x2 CurrentX sub) ->result
SetImageRotation(Self "main" <-result)


Aye, and a good day to ye!
-GameGibu

Yarr...

Thank you for making this GameGibu, You will be credited in the map i am making! (Not the creeper islands map, but the map after creeper islands which is coming soon! :) )
CW4 hype!!

GameGibu

Just a note, I wrote that code from scratch, entirely in the forum post box, on my mobile.  :o
It exists only here unless you have copied it already.
But maybe I should copy it because it looks so shiny and refined ;)

Yay me! Yay you! Yay everyone!  ;D ;D ;D
-GameGibu
Bringing you Custom maps since 2971!
☆CRPL Master☆