Turn In Place Without Moving

In previous games made in Pulp, I was able to fairly easily script this feature. However, with the addition of smoothly animated movement, I'm struggling to find where within the existing script where this needs to be coded. I've been banging my head against this for a few days now.

Since Pulp automatically will move the player according to directional input, the variables 'lastposx' and 'lastposy' are intended to store the previous player position before this directional input. The player can then be moved to this previous position if a turn without moving is detected, as stored in the variable 'turn=1'. At least that seemed to me to be the most straightforward way of doing this. But I've been unable to find where to place a 'goto lastposx,lastposy' statement without running into various problems due to the number of other events running at the same time.

If anyone would be willing to have a look at the attached file and help me out, it would be much appreciated!

(NOTE: the smooth animation script is derived from the excellent previous work of orkn with a few tweaks.)

Walk&TurnDemo.json.zip (7.1 KB)

I've fixed your problem

The thing about goto and its something that is not mentioned in the documentation is that it calls the player's update script when moving to one place. To avoid this, the variable standstill prevents the direction to be updated from goto, this is set to 1 in the same place as turn=1 and its also set to 0 when the player has moved as intended for good measure.

	// store current and last player positions
	if standstill==0 then
		lastpdx = pdx
		pdx = event.dx
		lastpdy = pdy
		pdy = event.dy
	end
on stop do
  	if standstill == 1 then
		goto lastposx,lastposy
		standstill = 0
	end
end

Here's the fixed json

Walk&TurnDemo.zip (6.7 KB)

1 Like

Cheers and fantastic spot! I wasn't thinking of update being called when goto is employed, although that makes sense because goto is another way of moving the player.

Hopefully, this feature and the related script will be useful to others who may find it here :space_invader:

1 Like