How to change values of FortCharacter's Position?

Hi,

I have a question about how to change values of FortCharacter’s Position.
Please look at the following Verse code.

I use FortCharacter.GetTransform() and get transform type value in ‘PlayerLocation’ variable.
I would like to change value of ‘Translation.Z’ and set it in the value.
What code should I use to do it?

Thank you.

    MethodA(Agent: agent)<suspends>:void =
                if (FortCharacter := Agent.GetFortCharacter[]):
                    PlayerLocation := FortCharacter.GetTransform()
                    # Change value of Translation.Z and set it in the variable  but this code causes this Error: ("The left hand side of this definition is an expression that cannot be defined.")
                    set PlayerLocation := PlayerLocation.Translation.Y + 10.0

The variable PlayerLocation is constant. Thus, you cannot use the keyword set to change the the value of PlayerLocation. To fix this you need to write var and specify the data type of the variable.
the line where you used the keyword set has 2 errors. One is that the syntax is wrong in set and you must use = not := when assigning a new value. Second thing is that the data type of PlayerLocation is transform (which is made up of location, rotation and scale but scale is ignored in case of a fort character) but you are trying to assign value of data type float. What you are looking for is to add two vectors rather than two floats. So your code should be this way:

# <suspends> is not needed in this case.
MethodA(Agent: agent):void =
  if (FortCharacter := Agent.GetFortCharacter[]):
      # Get the location of `Agent`
      var PlayerLocation : vector3 = FortCharacter.GetTransform().Translation
      # Change the value of `Z` in `PlayerLocation` by adding up two `vector3` values
      # The new variable `PlayerLocation` has no effect to `Agent`. It is just a variable
      set PlayerLocation = PlayerLocation + vector3 {Z:= 10.0}

Another thing to mention is to use .TeleportTo[:vector3, :rotation] if you want to change the position of the player. What you are doing is simply getting the exact transform of the player when the function MethodA was called and assign it to a new variable. Here is an example of how you use .TeleportTo[]:

TeleportPlayer(Agent: agent):void =
  if (FortCharacter := Agent.GetFortCharacter[]):
    Rotation:= FortCharacter.GetTransform().Rotation
    PosX:= FortCharacter.GetTransform().Translation.X
    PosY:= FortCharacter.GetTransform().Translation.Y
    PosZ:= FortCharacter.GetTransform().Translation.Z + 10.0
    NewLocation:= vector3 {X:= PosX, Y:= PosY, Z:= PosZ}
    if (FortCharacter.TeleportTo[NewLocation, Rotation]):

Thank you very much for your reply.

It makes sense. In addition to your first code, I would like to set the new vector information in the original player’s ‘transform’ type variable:

# <suspends> is not needed in this case.
MethodA(Agent: agent):void =
  if (FortCharacter := Agent.GetFortCharacter[]):
      # Get the location of `Agent`
      var PlayerLocation : vector3 = FortCharacter.GetTransform().Translation
      # Change the value of `Z` in `PlayerLocation` by adding up two `vector3` values
      # The new variable `PlayerLocation` has no effect to `Agent`. It is just a variable
      set PlayerLocation = PlayerLocation + vector3 {Z:= 10.0}
      var PlayerNewLocation: transform =  FortCharacter.GetTransform()
      set PlayerNewLocation = ?????....

Is it possible to do the above?

Thank you,

Yes, you can write it this way:

set PlayerNewLocation = transform {Translation:= PlayerLocation, Rotation:= FortCharacter.GetTransform().Rotation, Scale:= FortCharacter.GetTransform().Scale}

You can delete the rotation and scale if you don’t need them but It is worth mentioning that ignoring Translation, Rotation, or Scale will automatically assign them default values (1.0 for scale in x, y, and z and 0.0 for rotation in x, y and z).
Both transform & vector3 are struct. Check the documentation about struct for more information!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.