Page 1 of 1

Problems with LuaEntity.orientation

Posted: Sat Nov 13, 2021 2:51 pm
by Pi-C
LuaEntities have two properties that affect their direction: direction and orientation. The first is rather rough, the other more fine-grained. Only direction can be used with LuaSurface.create_entity.

Yesterday, I noticed something peculiar:

Code: Select all

    name = player.character.name
    position = player.character.position
    surface = player.surface
    force = player.force
    direction = player.character.direction
    orientation = player.character.orientation

    log("direction: " .. direction .. "\torientation: " .. orientation)

    player.character = surface.create_entity{name = name, position = position, direction = direction, force = force, fast_replace = true, raise_built = true}
    
    log("direction: " .. player.character.direction .. "\torientation: " .. player.character.orientation)
Before the character was replaced, I've logged these values:
direction: 3
orientation: 0.375

So the character was facing towards Southeast. After the new character had been created, I've got these values:
player.character.direction: 2
player.character.orientation: 0.25

So the character was facing eastwards. Now, I thought I'd adjust orientation to let the new character face SE again:

Code: Select all

    if player.character then
      player.character.orientation = orientation

      log("After changing orientation. direction: " .. player.character.direction .. "\torientation: " .. player.character.orientation)

    end
Surprise, surprise! The new character was still facing eastwards. However, this change did the trick:

Code: Select all

    if player.character then
      player.character.direction = direction

      log("After changing direction direction: " .. player.character.direction .. "\torientation: " .. player.character.orientation)

    end
The new character was finally looking into the same direction as the old one. However, the log still shows these values after applying the change to player.character.direction still :
player.character.direction: 2
player.character.orientation: 0.25

What's going on here?