Help with physic joint!

Hi guys! First of all I want to thank all of you for the help you offer here in the forum. This time I have doubt and I would like to get help. What would the best way to do a “physic joint weld” to achieve this?

The ball hits the four walls of the screen with a specific speed, but when it touches the surface of the blue square, I would like it not to move, I would like it to be welded in the center of the surface of the blue square.

to achieve it this is the code that I have:

local function jointObjects( event ) redBall.rotation = 0 --to make the image fill looks good redBall.x = blueRect.x redBall.y = blueRect.y-50 --position the redBall with the coordinates of the blueRect local joint = physics.newJoint( "weld", redBall, blueRect, redBall.x, redBall.y ) end

and I call the function on my local collision listener

jointDelay = timer.performWithDelay(1, jointObjects)

I read THIS but my

doubt is in "[font=‘Source Code Pro’]

anchor_x, anchor_y"

[/font]

[font=arial]

[font=‘Source Code Pro’]

[font=arial]

It is currently working but as it is the first time I do this I wanted to ask if it is ok.

[/font][/font][/font]

Or if there is any way to carry out this task other than using a joint?

[font=arial]

[font=‘Source Code Pro’]

[font=arial]

Thanks in advance

[/font][/font][/font]
[font=arial]

[font=‘Source Code Pro’]

[font=arial]

DoDi

[/font][/font][/font]

I just realized that I created this topic here when there is a physics section that could give me better results. If it is considered that it is out of place I will appreciate move the topic to the physic section to see if somebody can clarify the doubt.

Other thoughts:

If I change the redBall to static and change its position on collision can give better results?

I would like to carry out this task in a way that has been proven because my game depends on it and it would be quite intense to change the mechanics of attraction between the redBall and blueRect at 300 levels.

I’m not asking anyone to give me a code, I just need help to decide what would be the best way to get this result.

I actually don’t understand the question. 

You used the word doubt, but I think you mean question.

What is the question?  Your code looks OK. 

Maybe try giving us these key items in short numbered list.

  1. What you did.

  2. What you saw.

  3. What you expected to see.

From what I’ve read I think #1 is:

  1. You, implemented a collision detector that sensed when a red ball hit a blue block, and then called jointObjects() after a short delay.

I don’t know for sure what #2 and #3 are.

I say this a lot, but this is a perfect case where you should, fill out my list, and then make a tiny demo that shows this in action and demonstrates the issue.

Then, folks will download it and try it out.

I think you’re not getting response because:

a. The problem isn’t clearly defined.

b. It is too much work to guess.  This kind of thing needs testing and tweaking to help with.

@roamminggamer

Apologize, maybe I did not express myself well or the translator gave me grammatical errors.  

I’m going to reformulate the question.

  1. What value should be put in the “anchor_x” and in the “anchor_y” in the joint “weld” api?, that is my biggest question.

2) Which method would be better to use: a change of (“physical body” = method 1) or ("weld joint " = method 2) for the function “jointObjects” ?

note: I’m not using pre-collision listeners cause in the docs say they are noisy.

This is a kind of question, (doubt = nil), in which I am thinking redundantly something that should be simple for an experienced programmer, but for a newbie who wants to avoid long-term mistakes creates certain doubts, (doubt = method 1 or method 2) 

Not what I asked for.  I still have no idea what the problem is.  How is your code not doing what you want?

Why when I ask, do OPs always resist and resist?  I asked for something very easy to provide :frowning:

  1. Write a numbered list, 1, 2, 3 with the details I asked for in the format I asked for them.

  2. Provide tiny downloadable demo showing the problem.

This is a demo: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/10/dodiPhysics.zip

It contains two ways to do what I ‘think’ you are trying to do.

If not, how does the code not solve the problem?  What is wrong with the end result.

https://www.youtube.com/watch?v=xkTft1tjfFY&feature=youtu.be

PS - You’ve asked about the anchor <x,y> values.  My suggestion is, if they are mysterious, you can experiment with values to see what changing them does.  Us telling you what values to use won’t help you remember how they work in the long run.

Now that you have a ‘tiny’ demo you can play around with changes to see the side-effect.  

This is why I always tell users, "When you run into a problem, make a tiny test bench and experiment with the code or mechanic by itself. "  This clears up 99% of issues and confusions.  This is core practice in game development learning (as well as in other fields).

If you re-download the demo I linked, it will now have two more examples to help you further explore the concept of the weld joint and the side-effect of the anchor <x,y> values.

I just realized that I created this topic here when there is a physics section that could give me better results. If it is considered that it is out of place I will appreciate move the topic to the physic section to see if somebody can clarify the doubt.

Other thoughts:

If I change the redBall to static and change its position on collision can give better results?

I would like to carry out this task in a way that has been proven because my game depends on it and it would be quite intense to change the mechanics of attraction between the redBall and blueRect at 300 levels.

I’m not asking anyone to give me a code, I just need help to decide what would be the best way to get this result.

I actually don’t understand the question. 

You used the word doubt, but I think you mean question.

What is the question?  Your code looks OK. 

Maybe try giving us these key items in short numbered list.

  1. What you did.

  2. What you saw.

  3. What you expected to see.

From what I’ve read I think #1 is:

  1. You, implemented a collision detector that sensed when a red ball hit a blue block, and then called jointObjects() after a short delay.

I don’t know for sure what #2 and #3 are.

I say this a lot, but this is a perfect case where you should, fill out my list, and then make a tiny demo that shows this in action and demonstrates the issue.

Then, folks will download it and try it out.

I think you’re not getting response because:

a. The problem isn’t clearly defined.

b. It is too much work to guess.  This kind of thing needs testing and tweaking to help with.

@roamminggamer

Apologize, maybe I did not express myself well or the translator gave me grammatical errors.  

I’m going to reformulate the question.

  1. What value should be put in the “anchor_x” and in the “anchor_y” in the joint “weld” api?, that is my biggest question.

2) Which method would be better to use: a change of (“physical body” = method 1) or ("weld joint " = method 2) for the function “jointObjects” ?

note: I’m not using pre-collision listeners cause in the docs say they are noisy.

This is a kind of question, (doubt = nil), in which I am thinking redundantly something that should be simple for an experienced programmer, but for a newbie who wants to avoid long-term mistakes creates certain doubts, (doubt = method 1 or method 2) 

Not what I asked for.  I still have no idea what the problem is.  How is your code not doing what you want?

Why when I ask, do OPs always resist and resist?  I asked for something very easy to provide :frowning:

  1. Write a numbered list, 1, 2, 3 with the details I asked for in the format I asked for them.

  2. Provide tiny downloadable demo showing the problem.

This is a demo: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/10/dodiPhysics.zip

It contains two ways to do what I ‘think’ you are trying to do.

If not, how does the code not solve the problem?  What is wrong with the end result.

https://www.youtube.com/watch?v=xkTft1tjfFY&feature=youtu.be

PS - You’ve asked about the anchor <x,y> values.  My suggestion is, if they are mysterious, you can experiment with values to see what changing them does.  Us telling you what values to use won’t help you remember how they work in the long run.

Now that you have a ‘tiny’ demo you can play around with changes to see the side-effect.  

This is why I always tell users, "When you run into a problem, make a tiny test bench and experiment with the code or mechanic by itself. "  This clears up 99% of issues and confusions.  This is core practice in game development learning (as well as in other fields).

If you re-download the demo I linked, it will now have two more examples to help you further explore the concept of the weld joint and the side-effect of the anchor <x,y> values.