Page 1 of 1

Collision Mask modding question

Posted: Mon Mar 18, 2019 11:30 pm
by Hiladdar
Is there a way to change the collision mask of a player's avatar, from "player layer" to "object layer", based on the equipment placed into armor. If so, how would I do that.

Practical application in a mod would be like a piece of equipment inserted into armor, like a flotation device to allow swimming, or Prometheus' wings which gives flight?

Hiladdar

Re: Collision Mask modding question

Posted: Tue Mar 19, 2019 8:15 am
by darkfrei
On data stage make new character with new collision mask.
Check when the player places the (jet pack) to equipment.
Replace one character to custom one.
If no equipment or no energy then replace it back to standard.

Re: Collision Mask modding question

Posted: Tue Mar 19, 2019 4:51 pm
by Hiladdar
Thanks, for the guidance, I'll now work on breaking it down into substeps to implement as I am learning the APIs and lua.

Hiladdar

Re: Collision Mask modding question

Posted: Tue Mar 19, 2019 8:23 pm
by darkfrei
Links:

So if you makes in data.lua:

Code: Select all

local new_character = table.deepcopy (data.raw.player.player)
new_character.name = 'player-ghost'
new_character.collision_mask = {}
data:extend ({new_character})
Then with this console command
https://lua-api.factorio.com/latest/Lua ... ate_entity
you can create new one:

Code: Select all

/c game.player.surface.create_entity{name='player-ghost', position=game.player.position}
2019-03-19 21_23_02-Window.png
2019-03-19 21_23_02-Window.png (187.31 KiB) Viewed 1615 times
Then when you choose it and with command

Code: Select all

/c game.player.character = game.player.selected
you can change the character.
2019-03-19 21_26_31-Window.png
2019-03-19 21_26_31-Window.png (91.52 KiB) Viewed 1612 times
And it goes through water!
2019-03-19 21_27_19-Window.png
2019-03-19 21_27_19-Window.png (273.6 KiB) Viewed 1611 times

Re: Collision Mask modding question

Posted: Fri Mar 22, 2019 2:29 am
by Hiladdar
Thanks for the code segments. I finally had an opportunity to take detailed look at the samples you provided.

In order for the data.lua to work, i.e. for the short data.lua to be interpreted by Factorio, I had to make the following change to line 4:

Code: Select all

local new_character = table.deepcopy (data.raw.player.player)
new_character.name = 'player-ghost'
new_character.collision_mask = {}
data:extend ({new_character})
Starting the game up, and issuing the first console command works as expected, and produces a targeted new object.

But issuing the following console command:

Code: Select all

/c game.player.character = game.player.selected
produces an entirely different result. Both the original avatar and the newly created avatar do not move, but I can use the movement keys to move my avatar all over the map and explore map, while interacting with the various objects on the surface.

Doing a bit more research, I was able to figure out that default collision mask for objects is:

{"item-layer", "object-layer", "player-layer", "water-tile"}

So trying some different things, creating a one line entry in data-final-fixes.lua of:

Code: Select all

data.raw["player"]["player"]["collision_mask"] = {}
I was able to achieve the same effect with the player's avatar ignoring all the terrain effects.

I did some looking at code within other mods for programing examples, and came across Console Extended and Noxys Swimming. It looks like what Noxys does is remove the water-tile flag from water tiles, which allows players to walk on it. Console Extended is a bit more interesting, in that it has a number of console functions which modify aspects of the game. Of particular interest to me are examples of how the player mining and running speed is modified, and implemented. Along the same line, there there are a number of mods which modify the player's run speed or reach dynamically, based on a certain condition.

I do like your idea of having a periodic check, probably once per second, or once per 60 ticks to see if collision mask should be on or off for the avatar. I've still got quite a bit of learning, figuring out, and testing to do.

Hiladdar