Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Transition.to moving player through static physics objects
Started by nml2727 Nov 14 2019 10:09 AM

6 replies to this topic
transition.to collision physics static

Best Answer nml2727 , 14 November 2019 - 03:04 PM

If anyone stumbles upon this issue, I was able to make a workaround:

 

- Created a timer which stores the location of the player every second

- When the player runs into a wall or border

       - cancel the active transition on the player

       - use the stored location to figure out the direction the player was in before hitting the wall

       - transition the player in that direction by however much you want the player to "bounce" off the wall (i used a very short time for this transition)

       - I also disabled the touch listener during this short transition time and re-enabled it after

 

It's not the most elegant solution but it seems to get the job done and my character is no longer walking through walls.  :-) 

 

Thanks to XeduR @Spyric   for helping me think through this one.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

nml2727

[GLOBAL: userInfoPane.html]
nml2727
  • Enthusiast

  • 66 posts
  • Corona SDK

I have borders in my game which are static physics objects.  The player should NOT ever be allowed to move through them.  

 

My problem is that I am using transition.to for all my player movement and if I click on the other side of a physics border, the player walks right through the object, despite that it's static. 

 

I read that the way to handle this is by cancelling the transition.  

 

This only works if I just click one time.  But on the second click, the player proceeds to move across the border since the collision doesn't happen at that point.

 

Can anyone help me out with a way to stop the transition.to from moving through the static physics object?



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,020 posts
  • Corona SDK

In general, you don't want to use transitions to move around dynamic physics objects. I'm assuming your player is a dynamic object. The problem is that even though the physics engine tries to handle the player's movement, the transition is constantly fighting it and taking control and this will result in all sorts of weird behaviour. Then again, if your player is also a static physics object, then you run into the issue where only dynamic objects can collide with static objects to begin with.

 

If you must move physics objects with transitions, then make sure that the object you are moving doesn't have a dynamic type body.



[TOPIC: post.html]
#3

nml2727

[GLOBAL: userInfoPane.html]
nml2727
  • Enthusiast

  • 66 posts
  • Corona SDK

I actually don't need physics interaction with the player at all, except to prevent them from moving through walls.  I tried adding isSensor=true and just cancelling the transition when they hit the wall, but I still have the same problem, the 2nd time they try to move though the wall, since the onCollision doesn't happen again, they just walk right through. 



[TOPIC: post.html]
#4

nml2727

[GLOBAL: userInfoPane.html]
nml2727
  • Enthusiast

  • 66 posts
  • Corona SDK

Removing transitions and using forces would require a substantial amount of code to be rewritten so I'm trying to see if there's some trick I can use to get by for now that will stop the movement through the boundaries. 



[TOPIC: post.html]
#5

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,020 posts
  • Corona SDK

Well, the issue there is that you need to track when a collision begins and when it ends.

 

The collision event won't "begin" again before it has "ended". If you are stopping the transition when the player collides with the wall then you can only do so once because the collision won't stop until you move the player away from the wall, which won't happen until you give it a new movement order using your transition setup and move the player away from the wall, but at this point the player can just as well choose to move outside, i.e. you have a problem that requires extensive rewrites in any case.



[TOPIC: post.html]
#6

nml2727

[GLOBAL: userInfoPane.html]
nml2727
  • Enthusiast

  • 66 posts
  • Corona SDK

I'm toying with the idea of just making the player instantly explode if they hit a wall.   :D

 

Seems like the easiest solution for me.  =P



[TOPIC: post.html]
#7

nml2727

[GLOBAL: userInfoPane.html]
nml2727
  • Enthusiast

  • 66 posts
  • Corona SDK

  Best Answer

If anyone stumbles upon this issue, I was able to make a workaround:

 

- Created a timer which stores the location of the player every second

- When the player runs into a wall or border

       - cancel the active transition on the player

       - use the stored location to figure out the direction the player was in before hitting the wall

       - transition the player in that direction by however much you want the player to "bounce" off the wall (i used a very short time for this transition)

       - I also disabled the touch listener during this short transition time and re-enabled it after

 

It's not the most elegant solution but it seems to get the job done and my character is no longer walking through walls.  :-) 

 

Thanks to XeduR @Spyric   for helping me think through this one.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: transition.to, collision, physics, static