[Solved]Tilt vs Static Objects (goes through)

Ok I know this question has been asked before but never seem to have found a solution to it. If its for invisible walls or even an object that counts as your wall so characters stays on screen then you`re better off using a function to keep your character on screen with a Runtime event listener [IMO]. The real problem is if you have objects on screen that your character will collide against in a tilt base game no matter what changes I do to the character or static object the result is always the same. I tried changing the density or bounce to see if when character collides maybe it bounces back to avoid character going through the object. I even tried doing a little cheat like setting the character velocity to 0, 0 or if character collides from left side set linear velocity to -(number) , 0 to simulate a push but nothing seems to give good results. It seems with enough tilt the character will just go through or half way through the object! Is there a work around this?

Here is a sample to keep character on screen if you are wondering how. Obviously you will mess with the numbers base on your game and character size.
[lua]local function NameYourFunction(event)
– Left Side of screen
if YourCharacter.x < 20 then
YourCharacter.x = 20
end

– Right Side of screen
if YourCharacter.x > 300 then
YourCharacter.x = 300
end

– Top Side of screen
if YourCharacter.y < 0 then
YourCharacter.y = 0
end

– Bottom Side of screen
if YourCharacter.y > 480 then
YourCharacter.y = 480
end

Runtime:addEventListener(“enterFrame”, NameYourFunction) [import]uid: 30314 topic_id: 17721 reply_id: 317721[/import]

I guess im going to have to break my head on this one. Either corona apps dont use tilt much or people dont have a workaround for this problem. I know its not my game this has to be a physics problem with tilt and too much force (gravity). If I solve this ill post a solution [import]uid: 30314 topic_id: 17721 reply_id: 67565[/import]

Try playing around with physics.setVelocityIterations() and physics.setPositionIterations().

Sometimes the ‘step’ is not updated frequently enough and objects can go through one another. Also ensure that the object you are tilting is a ‘bullet’ object (isBullet = true).

You should also ensure that your static objects are not sleeping. Just keep tweaking and tweaking. If you absolutely cannot figure it out, then create a small test case that can isolate the bug with as few lines of code as possible, and upload it with a bug report.

Here is a link to the bug report form:
http://developer.anscamobile.com/content/bug-submission

But please try the other things I suggested first, to see if that fixes your problem before submitting a bug.

Good luck!
[import]uid: 52430 topic_id: 17721 reply_id: 67598[/import]

Hey Jon Thanks for the response I will keep tweaking around hopefully something will work I used .isBullet = true but same results. I used it on the character and then on both the character/object and it still going through I will keep messing around with numbers and tweaks and hopefully something will work but I think regardless is something with the physics engine? Supposedly a dynamic object should not go through a static object unless .isSensor = true if I remove the tilt and control my character via Buttons it works perfect even if u keep making character walk against the object it will never go through but the moment you use tilt it will go through. In my case i mess around so much it doesnt go through the whole object but a little less then half so Im hoping I figure this out soon.

Here is a link to this question asked months ago. I think this is a common problem for anyone who has use tilt and static objects they must had experienced it too.

link: https://developer.anscamobile.com/forum/2011/01/16/object-moves-through-wall-enough-tilt-0 [import]uid: 30314 topic_id: 17721 reply_id: 67611[/import]

have you put this line after physics.start() as jonathanbeebe has said

physics.setPositionIterations(32)

does your all static objects have enough thickness ? recommended 3 to 4 pixel

how you are moving your character with physics or manually by changing its position ? is it dynamic bodytype ?

remember if you are using anything like transition.to or manually moving objects can cause non physics behaviour resulting in some probs
:slight_smile: [import]uid: 12482 topic_id: 17721 reply_id: 67649[/import]

@ hgvyas123

Thanks for the response I have tried almost everything Possible the static objects are images 50x50 so there are thick enough, and yes all the code is after physics.start() the main character is dynamic with a radius of 30. The way the character is moved is by the player tilting the device left and right no transition.to I have tried messing with a few different numbers with physics.setVelocityIterations() and physics.setPositionIterations() but Ill keep trying different numbers hopefully one works. If I tilt it with enough force the character slowly penetrates the static object by about 1/4 of the static object size then it stops.
Here is my tilting code: (Landscape mode)
[lua] local function onAccelerate( event )
–motionx = 35 * event.xGravity
motiony = 25 * event.yGravity
end
Runtime:addEventListener (“accelerometer”, onAccelerate)

local function moveCharacter (event)
if(tilt == true)then

Character.x = Character.x - motiony

end
end

Runtime:addEventListener(“enterFrame”, moveCharacter) [import]uid: 30314 topic_id: 17721 reply_id: 67758[/import]

this line is the problem

[lua]Character.x = Character.x - motiony[/lua]

how?
i am trying to explain not sure whether i can or can not

imagine your obstacle is at (200,200) with width and height of 50
and your player is at (150,200) with 50x50 height and width so there is no collision right?

now your motiony = 10 so player will be at (160,200) at this time they are already overlapped and after this box2d can detect the collision may be when it detect the player will be at (170,200) more overlapping and as it will detect it will apply some force to the player to solve the overlapping issue but still motionY = 10 will do some embarrassing thing with it and you are seeing some what overlapping until it will solved
as i had said i try to explain may be it is the not exact theory which is happening it is just my guess.

may be you can use applyforce,linearvelocity, or even changing gravity in x direction to move your object.
:slight_smile: [import]uid: 12482 topic_id: 17721 reply_id: 67856[/import]

@hgvyas123 is correct. You are fighting the physics engine by updating the position of your character manually in the moveCharacter function. Any time you try to fight against the physics engine you will ALWAYS run in to problems. A great example of how to use the accelerometer for tilt control is the Shape Tumbler sample code here:
http://developer.anscamobile.com/content/shape-tumbler
The key function is this:
[lua]function onTilt( event )
physics.setGravity( ( 9.8 * event.xGravity ), ( -9.8 * event.yGravity ) )
end

Runtime:addEventListener( “accelerometer”, onTilt )[/lua]
By doing this you are using gravity to move the character so as not to upset the almighty Box2D. [import]uid: 27965 topic_id: 17721 reply_id: 67860[/import]

@ hgvyas123 / calebr2048

Thank you for your help I havent had a chance to try out your suggestions I been sick all day as soon as I get a chance Ill give it a shot and post the results. Not sure If I understand exactly what you guys mean but I got an idea of whats wrong thanks to both of you. Thanks again! [import]uid: 30314 topic_id: 17721 reply_id: 67912[/import]

welcome.

no need to understand much just try to use setLinearVelocity or gravity to move your character
:slight_smile: [import]uid: 12482 topic_id: 17721 reply_id: 67918[/import]

@ calebr2048

I tried the code you posted and It no longer goes through the static object the only problem is I cant get it to work according to my game. My game is landscape mode and character moves left and right according to your tilt and with the code you posted it works great not going through static object but is hard to control the character is floating up and down any idea how to fix it according to my game?

This is what im currently using which is what you posted Thanks:
[lua] function onTilt( event )
physics.setGravity( ( 9.8 * event.xGravity ), ( -9.8 * event.yGravity ) )
end

Runtime:addEventListener( “accelerometer”, onTilt ) [import]uid: 30314 topic_id: 17721 reply_id: 68014[/import]

If you only want tilt along a single axis (such as the x axis i.e. left and right) then you can change the function to something like this:
[lua]function onTilt( event )
physics.setGravity( ( 9.8 * event.xGravity ), 0 )
end

Runtime:addEventListener( “accelerometer”, onTilt )[/lua]
A way I’ve found to improve control is to change the physics.setScale() to something high (the default is 60). I usually set it to somewhere between 80 and 120 depending on how fast I want the character to change directions and/or speed up. [import]uid: 27965 topic_id: 17721 reply_id: 68027[/import]

Once again thanks everyone for all your help I had gave up on tilt and was going to use a D-pad to move my character but when I started this app the idea was to use tilt so here I am breaking my head once again any help is greatly appreciated this has been a very frustrating problem.

Ok so I learned how not to make character go through objects and the problem was as hgvyas123 and calebr2048 suggested (Thank You) So by using gravity to move character base on the sample code from Shape Tumbler there is a few problems with that. My character is supposed to jump when background is touched and by only allowing my character to move left and right with gravity my character floats when it jumps as if there is no gravity. I would think even if my gravity is set to (0.9.8) the moment I tilt I change the gravity? The other problem is if character stays standing for a certain amount of time its no longer move-able with tilt even if sleeping is not allowed and body active are on my favor I would think is as if the character by standing is continuously moving downward with gravity and its in somewhat of a “Stuck” position?

So now im ready to try to move my character with setLinearVelocity as suggested above but how can I accomplish this using tilt? how will it know when its left and right?

This is the code I was using to move left and right but it causes character to float, my game is intended to run in landscape mode. Thank You very much for all the help!

[lua]function onTilt( event )

physics.setGravity( ( 9.8 * event.yGravity ), 0 )

end

Runtime:addEventListener( “accelerometer”, onTilt ) [import]uid: 30314 topic_id: 17721 reply_id: 71822[/import]

Finally solved it and all I can advice for anyone who has this type of trouble you need to TEST out so many different values eventually one will fit your needs and the frustrating part is Simulator doesnt support Accelerometer so you test on device constantly. There is an app that allows Simulator to work with Accelerometer and other great features but I myself have not test it out yet.

cheers,
Chris L. [import]uid: 30314 topic_id: 17721 reply_id: 71854[/import]

Hi guys!

I’ve got the same problem. A wall and an object. With enough tilt the object goes trough the wall.
I was trying what people says here http://developer.anscamobile.com/node/5100, trying what Jonathan Beebe says on this post http://blog.anscamobile.com/2011/08/solutions-to-common-physics-challenges/
and till find this post I was so disappointed.

My tilt function seems like this:

local onTilt = function( event )   
 playerObject.x = playerObject.x - (playerObject.speed \* event.yGravity)  
end  

My player moves on x axis, as you can see.
I think the solution is, as @hgvyas123 says, use applyforce,linearvelocity, or even changing gravity in x direction to move your object.
I am newbee, so I appreciate so much if you could tell me how to change the sentence used to move the player.
There are more objects on the screen, so changing the gravity seems not to be the solution because these must be fixed (they are set to “dinamic”, like the player)

Any help will be appreciate!

[import]uid: 44013 topic_id: 17721 reply_id: 104642[/import]