Actor to rotate according to gravity when using drag and drop

Mr Goulden

  • *
  • Posts: 14
Hi All,

I'm looking to make a (what I thought was) simple drag and drop block game to build towers etc. I've seen and used the 'Follow Drag and Drop' behaviour, this works wonderfully fine but I wanted to take this a little further and have the block I pick up to rotate, through gravity according to where I 'pick up' the shape.

I.e. A rectangle is laid horizontally. If I click and drag near the left hand edge and lift it directly upwards, I want the right side to drop freely so that the rectangle becomes horizontal.

A couple of thoughts I've had:
  • Create a joint using the joints extension - couldn't get this to work.
  • Whilst dragging, temporarily set the actors centre of mass to the mouse position - no idea how to go about doing this.

If anyone has any ideas/thoughts, I'd appreciate it.

Many thanks

LIBERADO

  • *
  • Posts: 2718
When  you 'pick up' a shape:
 
- Create an invisible axis actor at the mouse position.
- Create a revolute joint between the axis actor and the shape actor.
- Create a mouse joint for the axis actor.
- Set the angular damping to 10 for the shape actor.


« Last Edit: June 16, 2020, 04:31:07 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

Mr Goulden

  • *
  • Posts: 14
What a legend Liberado!

That works beautifully, just a few tweaks to slow things down and it's exactly what I was looking for. I had thought about creating an invisible actor and creating joints between them but I would have not been able to do things so efficiently like you have. Truly excellent.

Thank you, I hope I didn't take up too much of your time.