Animate the angle of a switch upon collision from just one side

I have a lever switch (imagine a stick pointing up and to the left), and want to tween the angle to have it rotate to point to the upper right when the player’s sprite hits it from the left, but not the right. But, I can’t figure it out.

I was able to get it to change angle of the switch’s sprite upon collision, but I couldn’t get tweening to work. Nor could I figure out how to limit it being triggered if only from one side. Here’s is what I had for the tweening.

You should place an invisible detector object on each side and use two sets of events with two conditions each:

  • the left/right detector is in collision with MainChar
  • angle of Lever is -25/65

Is that a sprite with no graphics? I’ve never done that.

Also, the character is always swinging left to right or right to left using physics. So they would hit both detectors within less than a second. Can I have a condition based on what order they are collided with? If so, how?

I would just add a custom point to the left side of the switch (whereever the stick starts), and then confirm that point is inside the player (There’s a condition called “point is inside object”) AS WELL AS check that the Player’s X position is < than the switch X position, because X position increases from left to right.

Those two conditions being true would mean the player has to be touching the lever but also be to the left of it.

1 Like

Create a sprite, give it a plain black image to get a hitbox, place it on the scene, resize as you like and use an action to hide the object at the beginning of the scene (or use a custom point on the lever object, as suggested above).

For that, you could toggle a boolean hitleftfirst or hitrightfirst depending on which side is hit, and check for the second hit.