Jump to content

Pos. TranslateTo, Math


antstubell

Recommended Posts

So I'm just geting to grips with Pos. and wrote a small script which as usual brain says "Huh. Don't get it."

Here's the script that does nothing at the moment but sets up the structure. it compiles and saves - no problem.

 

Bool Property MoveToRef = True Auto


Float Property RotationVal Auto
Float Property SpeedVal Auto
Float Property Time Auto
Float Property Pause Auto
GlobalVariable Property StateGlobal Auto
ObjectReference Property EnPreMove1 Auto; steam
ObjectReference Property EnPreMove2 Auto
ObjectReference Property DisPostMove Auto
ObjectReference Property EnPostMove Auto
ObjectReference Property TranslateRef Auto
ObjectReference Property LocationRef Auto
ObjectReference Property SndMarker Auto
ObjectReference Property SndMarker0 Auto
Sound Property SFX Auto
Sound Property PreMovementSFX Auto
Sound Property SFX_End Auto
String Property BUSYMSG Auto

Event OnInit()

Float CurrentAngleX = TranslateRef.GetAngleX(); get turn left right angle
Float CurrentAngleY = TranslateRef.GetAngleY(); get rotate left right angle
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get up down angle

Float CurrentPosX = TranslateRef.GetPositionX(); get X co-ords
Float CurrentPosY = TranslateRef.GetPositionY(); get Y co-ords
Float CurrentPosZ = TranslateRef.GetPositionZ(); get Z co-ords

GoToState("Stationary")
EndEvent

State Stationary ;The object is currently not moving and translation can be started.

Event OnActivate(ObjectReference akActionRef)

GoToState("Stationary")
EndEvent
EndState

 

Now I add a TranslateTo like this...

 

Bool Property MoveToRef = True Auto


Float Property RotationVal Auto
Float Property SpeedVal Auto
Float Property Time Auto
Float Property Pause Auto
GlobalVariable Property StateGlobal Auto
ObjectReference Property EnPreMove1 Auto; steam
ObjectReference Property EnPreMove2 Auto
ObjectReference Property DisPostMove Auto
ObjectReference Property EnPostMove Auto
ObjectReference Property TranslateRef Auto
ObjectReference Property LocationRef Auto
ObjectReference Property SndMarker Auto
ObjectReference Property SndMarker0 Auto
Sound Property SFX Auto
Sound Property PreMovementSFX Auto
Sound Property SFX_End Auto
String Property BUSYMSG Auto

Event OnInit()

Float CurrentAngleX = TranslateRef.GetAngleX(); get turn left right angle
Float CurrentAngleY = TranslateRef.GetAngleY(); get rotate left right angle
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get up down angle

Float CurrentPosX = TranslateRef.GetPositionX(); get X co-ords
Float CurrentPosY = TranslateRef.GetPositionY(); get Y co-ords
Float CurrentPosZ = TranslateRef.GetPositionZ(); get Z co-ords

GoToState("Stationary")
EndEvent

State Stationary ;The object is currently not moving and translation can be started.

Event OnActivate(ObjectReference akActionRef)

TranslateRef.TranslateTo(CurrentPosX, CurrentPosY, CurrentPosZ, CurrentAngleX, CurrentAngleY, CurrentAngleZ, SpeedVal, RotationVal)

GoToState("Stationary")
EndEvent
EndState

 

(41,25): variable CurrentPosX is undefined
and Y and Z and so on - every one.

Not getting it.

 

 

Link to comment
Share on other sites

You declared them in OnInit instead of OnActivate, it cannot see those variables for they are made private to OnInit.

By the way, those are what they are, positions in a certain cell. If you want actual coordinates, yes you will need some math. (I didn't bother with Z but just add z array etc if you want that). It's not necessary and probably wont work as expected for movement functions, since they are expecting positions, but yeah here you go:

 

 

 

Int[] Function GetCellCoordinates(ObjectReference akRef)
    ; Returns an array of this reference\s cell coordinates.
  
    int posX = akRef.GetPositionX() as int
    int posY = akRef.GetPositionY() as int
   
    if (posX < 0)
        posX = (posX / 4096) - 1
    else
        posX = posX / 4096
    endif
   
    if (posY < 0)
        posY = (posY / 4096) - 1
    else
        posY = posY / 4096
    endif
   
    Int[] CellCoordinates = new Int[2]
    CellCoordinates[0] = posX
    CellCoordinates[1] = posY
   
    return CellCoordinates
EndFunction

 

 

Edited by Rasikko
Link to comment
Share on other sites

The reason behind getting the co-ordinates of an object is based on this - watch video and you will see where my issue lies.

 

https://onedrive.live.com/?cid=B60C11D037429D8E&id=B60C11D037429D8E%2151479&parId=B60C11D037429D8E%21191&o=OneUp

 

As seen in the video I am using a translateto script, 2 in fact one for up/down and one for left/right which are placed on triggers. This works fine. But... the translations have fixed positions to translate to. The Up/down rotates through the X axis. left/right through the Z axis. For simplicity lets say 90 degrees is the amount I want to move the skull. When player first activates skull and for example chooses Up/Down the skull translates from it starting co-ordinates (set in properties) AngleX1,AngleY1,AngleZ1 to its Up co-ordinates (set in properties) AngleX2,AngleY2,AngleZ2. A global is now set which records 'Skull is in Up position' so if player selects Up/Down again it translates the opposite way. Same for left/right. The 2 scripts are assuming the starting co-ords. are correct regardless of where the skull has rotated to. As you see in the video this messes up the correct translation, sometimes it won't translate at all or move through a diagonal (which ain't so bad but does not follow what the option says).

I guess you can see what is wrong in the video. So my idea was "I need to get the current rotation of the skull, tell the script where it is and from there depending if Up/Down Left/Right is chosen, rotate the skull through 90 degrees." This sounded fine - hence my preoccupation of getting the current rotation. Eventually I though "This could present the situation where the skull could be completely rotated. Can't have that!" So next thought was whichever option is chosen skull will only rotate, through X or Z axis +/- 90 degrees so if player chose Left/Right and again Left/Right the first time Left/Right is selected it goes Right 90 degrees but the second time it goes Left 90 degrees. Same for Up/Down. Both case 90 degrees always being the maximum rotation.

Finally, the reason for all this rotating is player has to set the skull in a specific position left, right, up or down then 2 other skulls have to be set in correct positions. When all 3 skulls are in their correct positions, script needs to check this by if GetAngleX() = 90 && GetAngleX() = (I'm guessing this scripting is wrong too) then Do Stuff.

Long winded I know but I hope I got the idea across.

Thanks.

Link to comment
Share on other sites

Okay for some reason axis-I-sis are not what I expected them. X appears to be Z but... whatever.

Sorted out my check skull rotation script. This is the function that checks it.

 

Function CheckAngleZ()
Utility.wait(4.0); allow time for translation to finish
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get turn left right angle
if (CurrentAngleZ == AngleValue)
debug.notification("Looking Right. Global is 1")
Skull01Set.SetValue(1); skull1 is in place

ElseIf (CurrentAngleZ != AngleValue)
debug.notification("Nope. Global is 0")
Skull01Set.SetValue(0); skull1 is NOT in place

Endif
EndFunction

 

Link to comment
Share on other sites

As I told you, Skyrim uses left handed rotation(I put it in simple terms, but it's really left intrinsic). This means the rotation is not the real world order of XYZ, but the reverse.

 

Thus, when an object is rotating left or right, it is rotating on the Z axis, not the X.

Edited by Rasikko
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...