Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Moving a physics object with transition.to ?
Started by d.mach Apr 04 2019 02:05 AM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 821 posts
  • Corona SDK

I know moving a physics object directly with transition.to is fighting the physics engine BUT I wonder if it is possible to somehow use a joint to manipulate (move) a physics body to a screen position with transition.to ?

 

I am working with a Touchjoint right now but it is manipulated by using :setTarget( newxval,newyval )

 

Is there a way (for example) to use translate.to to manipulate the :setTarget?

 

Can this be done another way?



[TOPIC: post.html]
#2

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

There's another thread where the joint has been suggested and I've posted quite a bit on this in the past.

 

So, specifically, you want to use transition.* to move a physics object. For this you need to put together a number of things...

 

You need something which can be transitioned, something to move the physics object and something with a joint.

 

First option: Static body as anchor, joined to the dynamic body. Use a transition on the static body (this is ok because it's not fighting Box2D), create a weld joint between the static body and the dynamic body.

 

Second option: Display object as a tracker, enterFrame listener to control the touch joint. Create a display object (eg: group) at the same location as the point on the dynamic body where you want the touch joint to be attached to the dynamic body. Create the touch joint and store a reference to it on the display object (in this case, a group.) Create an enterFrame listener to call setTarget on the touch joint (referenced by the display group) to whatever world location the display group is currently at. Create the transition to move the display object.

 

The first option will give you much more precise control, but some will worry that it will cause problems and tbh there is no way to guarantee that it won't because it is technically breaking the rules. But I've used it fairly reliably.

 

The precision of the second option comes down to the design of the touch joint. How strong do you make it relative to the size and density of the object being controlled.



[TOPIC: post.html]
#3

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 821 posts
  • Corona SDK

Thanks for your help!

 

Your first option seems like the exact thing I need, so I have build it. But now I have another problem:

 

I can move the static body but it is not moving the dynamic body. Even with a weld joint between both the dynamic body just stays at it's first position. The weld joint "line" is getting longer and longer when the static body is moved but nothing else happens.

 

What did I miss?

 

UPDATE:

 

Forgot to add .isSleepingAllowed = true

Now it is working.

 

I noticed using a "sensor" object even works better than the "static" one because there are no collisions with the sensor AND when working with maskedBits you can just collide with whatever you want.

 

Great way to move things around!

Thank you again!




[topic_controls]
[/topic_controls]