Changing player orientation to match room layout

I stumbled across this problem in my game and maybe my solution will help someone else:
I want to change the player direction to match the wall they are standing on:

movement

Having the wall tiles turn the player is error-prone, so I'm doing the work in the player

// analyze room layout
on enter do
	x = 0
	xStart = 0
	xEnd = 0
	while x<=24 do
		tileName = name x,14
		if tileName=="cornerLeft" then
			xStart = x
		elseif tileName=="cornerRight" then
			xEnd = x
		end
		x++
	end
end

// turn player
on update do
	shrinkFactor = event.y
	
	if xStart != xEnd then
  	if event.y<=10 then
  		// top area and middle area
  		if shrinkFactor>4 then
  			shrinkFactor = 4
  		end
  		
  		emit "calculateShrinkage"
  		
  		if event.x<xStartEffective then
  			swap "playerWest"
  		elseif event.x>xEndEffective then
  			swap "playerEast"
  		else
  			swap "player"
  		end
  	else
  		// bottom area
  		shrinkFactor -= 14
  		shrinkFactor *= -1
  		
  		emit "calculateShrinkage"
  		
  		if event.x<xStartEffective then
  			swap "playerWest"
  		elseif event.x>xEndEffective then
  			swap "playerEast"
  		else
  			swap "playerSouth"
  		end
  	end
	end
end

on calculateShrinkage do
	xStartEffective = xStart
	xStartEffective += shrinkFactor
	xEndEffective = xEnd
	xEndEffective -= shrinkFactor
end

This works for different width rooms, because it measures the distance between the bottom corner tiles. From that the room layout is calculated and the player turned.

No idea how I might use this but it's very cool!

I'm not sure what your game is, but I was expecting the player's feet to touch the wall.

1 Like

Thanks!
You mean you were expecting the player to have really long legs when they move along the wall? That would make sense visually.

Ha ha no not that. I was expecting the head to face inwards!
But what do I know? I don't really have the context to understand what's going on.

Cool stuff none the less!

1 Like

Ah, now I get it! I'll try that!
Yes, that's actually a lot better:

Bildschirmaufnahme 2022-02-05 um 10.19.30

on enter do
	x = 0
	xStart = 0
	xEnd = 0
	while x<=24 do
		tileName = name x,14
		if tileName=="cornerLeft" then
			xStart = x
		elseif tileName=="cornerRight" then
			xEnd = x
		end
		x++
	end
end

on update do
	shrinkFactor = event.y
	
	if xStart != xEnd then
  	if event.y<=4 then
  		// top area
  		emit "calculateShrinkage"
  		
  		if event.x<xStartEffective then
  			swap "playerEast"
  		elseif event.x>xEndEffective then
  			swap "playerWest"
  		else
  			swap "playerSouth"
  		end
  	else
  		// bottom area and middle area
  		shrinkFactor -= 14
  		shrinkFactor *= -1
  		
  		if shrinkFactor>4 then
  			shrinkFactor = 4
  		end
  		
  		emit "calculateShrinkage"
  		
  		if event.x<xStartEffective then
  			swap "playerEast"
  		elseif event.x>xEndEffective then
  			swap "playerWest"
  		else
  			swap "player"
  		end
  	end
	end
end

on calculateShrinkage do
	xStartEffective = xStart
	xStartEffective += shrinkFactor
	xEndEffective = xEnd
	xEndEffective -= shrinkFactor
end
1 Like