Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some player animations get broken, when registered with player_api #149

Open
axcore opened this issue Dec 7, 2024 · 0 comments
Open

Some player animations get broken, when registered with player_api #149

axcore opened this issue Dec 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@axcore
Copy link

axcore commented Dec 7, 2024

For example, the player will stand on a bed, rather than lying on it (90% of the time).

Here's the broken code, in 3d_armor/init.lua:

player_api.register_model("3d_armor_character.b3d", {
	animation_speed = 30,
	textures = {
		armor.default_skin..".png",
		"blank.png",
		"blank.png",
	},
	animations = {
		stand = {x=0, y=79},
		lay = {x=162, y=166},
		walk = {x=168, y=187},
		mine = {x=189, y=198},
		walk_mine = {x=200, y=219},
		sit = {x=81, y=160},
		-- compatibility w/ the emote mod
		wave = {x = 192, y = 196, override_local = true},
		point = {x = 196, y = 196, override_local = true},
		freeze = {x = 205, y = 205, override_local = true},
	},
})
`

Compare the call to the same function, from minetest_game/player_api/init.lua:

`
player_api.register_model("character.b3d", {
	animation_speed = 30,
	textures = {"character.png"},
	animations = {
		-- Standard animations.
		stand     = {x = 0,   y = 79},
		lay       = {x = 162, y = 166, eye_height = 0.3, override_local = true,
			collisionbox = {-0.6, 0.0, -0.6, 0.6, 0.3, 0.6}},
		walk      = {x = 168, y = 187},
		mine      = {x = 189, y = 198},
		walk_mine = {x = 200, y = 219},
		sit       = {x = 81,  y = 160, eye_height = 0.8, override_local = true,
			collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.0, 0.3}}
	},
	collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
	stepheight = 0.6,
	eye_height = 1.47,
})

Because 3darmor's call to player_api.register_model() does not provide values for .eye_height, .stepheight and .collisionbox, the following happens during the call to player_api.register_model():

  1. The table is given default values for .eye_height, .stepheight and .collisionbox
  2. These values are then copied into each mini-table. Thus, both stand and lay now have the same value for .eye_height (which is obviously wrong)
  3. The player_api code notices that most of the animations have the same values, so it maps them onto each other (using the .equals field, in line 42). Thus, most of the animations are now completely wrong

The solution (which I have tested) is to change the table in 3d_armor's call to player_api.register_model() so it's the same as player_api's own call to player_api.register_model().

@BuckarooBanzay BuckarooBanzay added the bug Something isn't working label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants