Physics spasm?

Hey guys, this is kind of a complex question cause i dont speak ensligh very well, and its hard to explain.

So im still doing this app with the guy holding a lantern and killing little ghosts when they get into the path of the light, at one point i had to do the collision detector between the lantern and the ghosts, i had no idea on how to do this, since the lantern is part of the guy.png (it doesnt have it own reference points, dependes on guy.x,guy.y)

What i made was create 2 circles in the extremes of the lantern, and use a function that determines if the ghosts x and y are inside the triangle formed by the circles coords and the guy coords, this was ok to do, but the problem now is that the guy rotates around, so i wasnt sure how to make the circles follow the guy rotation, then i had the idea to include physics and use a weld joint between the 3 objects, this worked almost perfectly, but the problem and the reason of this post is that since i included the physics, when i move around my guy with my mouse(holding touch on android) the guy sometimes randomly spasms around, moving the lanter in all directions, for about half a second, it happens very often, i removed the alpha on the little circles to check what was happening, and it appears like they teleport around the screen during that spasm, im not sure why, if its some sort of collision, or because of moving fast (its not that fast) or the weld joint, i dont know, but its really bothering me and making it almost unplayable.

I read you could make the guy and the 2 dots part of the same “object” will i be able to use the dots x and y and the guy x and y to make the triangle even if they’re into the same object? if so, how can i make an object like that? I know it seems really confusing. I hope any of u could understand what im trying to explain (Rob please!)

I could supply you the full code (around 300 lines) in a zip or something, or the .apk for you to try and see what im trying to describe, i have no idea on how to fix this.

ref.png

That’s the guy x and y and the two little circles, however the guy object is the whole thing, from the body to the end of the lantern. 

Edit: excuse my english, if you dont understand i will try to explain myself better, even if i find it really hard since i dont know how to explain this lol.

Edit: added a youtube video just to show you the spasms, this is how concerned i am about this thing.

http://www.youtube.com/watch?v=ZnpciloSSjQ

Spasms happens at 00:07 and 00:19, and probably at the start.

Edit: added new video with drawmode set to hybrid, hope this helps to know what’s going on. (thanks Burhan).

http://www.youtube.com/watch?v=DBi8L7PmlOw

Spasms happens everywhere, even i died because of one, thats gamebreaking.

Hi @tuku473

Maybe you could try multi element physics.

Read tutorial from Brent here http://coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/

And if you need to check your physics range or status use physics.setDrawMode( “hybrid” )

Good Luck!

burhan

hey burhan, thanks for your reply, i tried to do that tutorial but was getting some sort of error when tried to add the body, and was really later last night, so i stopped and decided to deal with this thing today, i’m really trying to understand how to make the body like that, i just uploaded a video there to show the random spasms, maybe it helps to clarify whats going on.

Edit: i enabled the hybrid mode and what happens with the dots is pretty messy, im uploading a new video right now, will be done in a few minutes, thanks burhan, i hope we could solve this

hi!

Pretty messy right? It should not be called weld joint because the joint becomes weak under quick movement.

I would go for multi-element physics to save all the troubles.

burhan

Just an idea.

Maybe you can try changing the 2 circles to one trapezoid body shape.

Make the 2 bodies of the man and light as close as possible than set the weld joint.

Hopefully it sticks better. You may want to play with density and friction of the 2 bodies too.

Hey burhan, actually thanks to you i found a huge error i had, when i made the joints i made them like this:

local ext1j = physics.newJoint( “weld”, ext1, guy, guy.x, guy.y)

local ext2j = physics.newJoint( “weld”, ext2, guy, guy.x, guy.y)

local p2pj = physics.newJoint(“weld”,ext1,ext2,guy.x,guy.y)

I dont know why (probably because of the hour) i used guy.x and guy.y as the anchors for the join between the points 1 and 2, but apparently that was causing everything to collide like in the video (probably because it has to do like a V join or maybe cause there were already 2 joints there aswell, from 1 to guy and from 2 to guy) so i just removed that third joint and actually everything worked pretty fine.

So yeah, problem pretty much solved thanks to your drawmode hybrid suggestion :slight_smile: thanks again!

Now im trying to implement those 300 lines of code into a storyboard, im super lost here, i dont know where to put the functions, where to put the variables, the listeners, etc etc etc, i keep getting errors wherever i put them, i get errors if i do group:insert(variable) even if i just declared it, i get errors if i try to call a variable from one of the storyboard functions to the other, i get errors for trying to operate with nil stuff when those nils arent variables, they’re arguments the function recieves, etc.

I’ll probably make a post about it soon about it lol.

I’m not sure if you can get all your code and then just throw it into storyboard just like that, idk, i still dont understand them that much.

I’m happy for you.

Ok let’s put your storyboard question on a different post. It will be easier for others who wants to find help, search base on topic.

You can somehow “throw” your code but they have to be in the right slots (scene functions). :wink:

I’m sure you have started reading tutorials here. Rob has made excellent storyboard tutorials.

Always been a fan of the tutorials here.

burhan

Hey burhan, yes i always read tutorials to understand what’s going on, i actually read this one http://www.develephant.net/a-simple-storyboard-framework-for-corona-sdk-part-1/ about storyboards, and was understanding pretty much everything, i actually made myself already the diferent .luas i want for my game, and made all the menus and stuff i want, the problem with that tutorial (and also the Corona documentation itself) its that i dont finish to understand the diferent “phases” of the storyboard, or when to declare what, in that tutorial there are some functions outside the storyboard blocks, and oh well, nvm i will try to put the things together and make a new post about this

I would totally throw my code but i really dont wanna bother anyone with 300 lines of code probably full of errors :P, i will end up doing it anyways, since i have no idea where to put everything and if its even possible to put my game as it is inside a storyboard ;_;

Thanks as usual for your reply and im happy we solved that thing :slight_smile:

Hi @tuku473

Maybe you could try multi element physics.

Read tutorial from Brent here http://coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/

And if you need to check your physics range or status use physics.setDrawMode( “hybrid” )

Good Luck!

burhan

hey burhan, thanks for your reply, i tried to do that tutorial but was getting some sort of error when tried to add the body, and was really later last night, so i stopped and decided to deal with this thing today, i’m really trying to understand how to make the body like that, i just uploaded a video there to show the random spasms, maybe it helps to clarify whats going on.

Edit: i enabled the hybrid mode and what happens with the dots is pretty messy, im uploading a new video right now, will be done in a few minutes, thanks burhan, i hope we could solve this

hi!

Pretty messy right? It should not be called weld joint because the joint becomes weak under quick movement.

I would go for multi-element physics to save all the troubles.

burhan

Just an idea.

Maybe you can try changing the 2 circles to one trapezoid body shape.

Make the 2 bodies of the man and light as close as possible than set the weld joint.

Hopefully it sticks better. You may want to play with density and friction of the 2 bodies too.

Hey burhan, actually thanks to you i found a huge error i had, when i made the joints i made them like this:

local ext1j = physics.newJoint( “weld”, ext1, guy, guy.x, guy.y)

local ext2j = physics.newJoint( “weld”, ext2, guy, guy.x, guy.y)

local p2pj = physics.newJoint(“weld”,ext1,ext2,guy.x,guy.y)

I dont know why (probably because of the hour) i used guy.x and guy.y as the anchors for the join between the points 1 and 2, but apparently that was causing everything to collide like in the video (probably because it has to do like a V join or maybe cause there were already 2 joints there aswell, from 1 to guy and from 2 to guy) so i just removed that third joint and actually everything worked pretty fine.

So yeah, problem pretty much solved thanks to your drawmode hybrid suggestion :slight_smile: thanks again!

Now im trying to implement those 300 lines of code into a storyboard, im super lost here, i dont know where to put the functions, where to put the variables, the listeners, etc etc etc, i keep getting errors wherever i put them, i get errors if i do group:insert(variable) even if i just declared it, i get errors if i try to call a variable from one of the storyboard functions to the other, i get errors for trying to operate with nil stuff when those nils arent variables, they’re arguments the function recieves, etc.

I’ll probably make a post about it soon about it lol.

I’m not sure if you can get all your code and then just throw it into storyboard just like that, idk, i still dont understand them that much.

I’m happy for you.

Ok let’s put your storyboard question on a different post. It will be easier for others who wants to find help, search base on topic.

You can somehow “throw” your code but they have to be in the right slots (scene functions). :wink:

I’m sure you have started reading tutorials here. Rob has made excellent storyboard tutorials.

Always been a fan of the tutorials here.

burhan

Hey burhan, yes i always read tutorials to understand what’s going on, i actually read this one http://www.develephant.net/a-simple-storyboard-framework-for-corona-sdk-part-1/ about storyboards, and was understanding pretty much everything, i actually made myself already the diferent .luas i want for my game, and made all the menus and stuff i want, the problem with that tutorial (and also the Corona documentation itself) its that i dont finish to understand the diferent “phases” of the storyboard, or when to declare what, in that tutorial there are some functions outside the storyboard blocks, and oh well, nvm i will try to put the things together and make a new post about this

I would totally throw my code but i really dont wanna bother anyone with 300 lines of code probably full of errors :P, i will end up doing it anyways, since i have no idea where to put everything and if its even possible to put my game as it is inside a storyboard ;_;

Thanks as usual for your reply and im happy we solved that thing :slight_smile: