Opposite image rotation

Started by Nicant, June 11, 2017, 07:11:14 PM

Previous topic - Next topic

Nicant

I'm making a creeper turret that fires creeper blobs at player structures. Everything is perfect except the turret rotating correctly. The turret rotates almost opposite to where it is actually supposed to point.
Here's code:
# Creeper Sprayer.crpl
# Created on: 6/11/2017 4:39:30 PM
# ------------------------------------------

once
Self "main" "Custom0" SetImage
Self "Turret" "Custom1" SetImage
Self "main" 1 SetImagePositionZ
0 SetTimer0
endonce

GetTimer0 eq0 if
CurrentCoords 25 GetUnitCountInRange 1 gte if
CurrentCoords 25 GetUnitsInRange ->Number ->Unit
<-Unit CONST_COORDX GetUnitAttribute ->X
<-Unit CONST_COORDY GetUnitAttribute ->Y
CurrentY <-Y sub ->YY
CurrentX <-X sub ->XX
<-YY <-XX atan2 ->Angle
Self "Turret" <-Angle SetImageRotation
"CRPLCORE" CurrentCoords CreateUnit ->Blob
<-Blob "Bullet.crpl" AddScriptToUnit
<-Blob "Bullet.crpl" "targetX" <-X SetScriptVar
<-Blob "Bullet.crpl" "targetY" <-Y SetScriptVar
60 SetTimer0
endif
endif
CW4 hype!!

GoodMorning

Code (in general) Select
<-Angle PI add ->Angle

...although you can inline it here.
A narrative is a lightly-marked path to another reality.

Nicant

I put that in my code and it has almost no effect.
CW4 hype!!

GoodMorning

# Creeper Sprayer.crpl
# Created on: 6/11/2017 4:39:30 PM
# ------------------------------------------

once
Self "main" "Custom0" SetImage
Self "Turret" "Custom1" SetImage
Self "main" 1 SetImagePositionZ
0 SetTimer0
endonce

GetTimer0 eq0 if
CurrentCoords 25 GetUnitCountInRange 1 gte if
CurrentCoords 25 GetUnitsInRange ->Number ->Unit
<-Unit CONST_COORDX GetUnitAttribute ->X
<-Unit CONST_COORDY GetUnitAttribute ->Y
CurrentY <-Y sub ->YY
CurrentX <-X sub ->XX
<-YY <-XX atan2 PI add ->Angle #Changed....
Self "Turret" <-Angle SetImageRotation
"CRPLCORE" CurrentCoords CreateUnit ->Blob
<-Blob "Bullet.crpl" AddScriptToUnit
<-Blob "Bullet.crpl" "targetX" <-X SetScriptVar
<-Blob "Bullet.crpl" "targetY" <-Y SetScriptVar
60 SetTimer0
endif
endif


Does this work? All it should be doing is turning the image around.
A narrative is a lightly-marked path to another reality.

Nicant

Nope, still does not work... This is what i see
Spoiler
[close]
CW4 hype!!

GoodMorning

I'd expect that it would have been facing SW, and is now pointing NE. That being the case, substitute "PI 2 div sub" for "PI add" and it should help.

Unless I've misread the code severely, then the issue is that the Sprayer image selected as Custom1 is not facing right. So offsetting by "PI" or "PI 2 div" twists it to the expected angle.
A narrative is a lightly-marked path to another reality.

Nicant

PI 2 div sub does same as before
Pi 2 div makes the thing look up
CW4 hype!!

GoodMorning

I'm going to feel extremely stupid when I work out what I have gotten wrong.

May I have a save to fiddle with?
A narrative is a lightly-marked path to another reality.

Nicant

CW4 hype!!

GoodMorning

This one works.
# Creeper Sprayer.crpl
# Created on: 6/11/2017 4:39:30 PM
# ------------------------------------------

once
Self "main" "Custom0" SetImage
Self "Turret" "Custom1" SetImage
Self "main" 1 SetImagePositionZ
0 SetTimer0
endonce

GetTimer0 eq0 if
CurrentCoords 25 GetUnitCountInRange 1 gte if
CurrentCoords 25 GetUnitsInRange ->Number ->Unit
<-Unit CONST_COORDX GetUnitAttribute ->X
<-Unit CONST_COORDY GetUnitAttribute ->Y
CurrentY <-Y sub ->YY
CurrentX <-X sub ->XX
<-YY <-XX neg atan2 ->Angle #Changed....
Self "Turret" <-Angle SetImageRotation
"CRPLCORE" CurrentCoords CreateUnit ->Blob
<-Blob "Bullet.crpl" AddScriptToUnit
<-Blob "Bullet.crpl" "targetX" <-X SetScriptVar
<-Blob "Bullet.crpl" "targetY" <-Y SetScriptVar
60 SetTimer0
endif
endif


The issue was that CW3 (like some HTML environments) increases Y going "South" - conventionally, Y increases going "North" (PF does this). So flipping the correct sign makes the problem go away. In point of fact, this is the optimised way to flip both signs ((XX,YY) is pointing in the opposite direction) and then flip the Y sign again. Y flips twice, getting back where it started, X flips once, which is the point of the "neg" I added.

Yes... I am feeling foolish, but at least it was something I know I forgot about from not having used the CW3 editor for a while. Sorry to have taken so much of your time with trying to fix what wasn't broken.
A narrative is a lightly-marked path to another reality.

Nicant

It is ok, i had to double check some of my commands in the script because i'm used to Prpl. Thanks for the fix!  :)
CW4 hype!!