playMaker

Author Topic: Add velocity to object based on drag velocity  (Read 6093 times)

OleP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Add velocity to object based on drag velocity
« on: February 15, 2012, 05:58:20 AM »
Hi there.
I've made a FSM to drag and drop a gameobject on a plane(based on the MouseClickToDrag sample). But when I release the gameobject, I want to add velocity to it, based on the velocity it had on the point of release. The goal is to make the gameobject behave like an ice puck, and bounce around inside a 2D frame.

 I currently got 5 states:
Wait for click -> Clicked world? -> clicked object? -> drag object -> add velocity

On the "drag object" state, I've added a "Get Velocity" action, and stored it into a vector3 variable. On the "add velocity" state, I've added a "Add Velocity" action, and chosen the vector3 variable as source.

And here comes the problem: How do I measure the velocity the gameobject has on the point of release? I'm using "Mouse Pick" and "Set position", but when I drag it around, it dosen't measure any velocity.


I hope I've explained it well enough for you guys to understand. If not, I can post the whole project for you.
If you know another way to do this, feel free to post the suggestion.
« Last Edit: February 15, 2012, 06:00:31 AM by OleP »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #1 on: February 16, 2012, 02:50:06 AM »
Hi,

 To measure velocity,  store the delta position between two updates and the also the deltatime that goes with it. the velocity is then the deltaposition magnitude divided by the deltatime it took.

The speed would be then expressed in unity/seconds.

Is that clearer? Or do you know this already and have problem implementing it in playmaker?

Bye,

 Jean


 

OleP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #2 on: February 16, 2012, 03:14:18 AM »
Thank you.

It sure makes sense when you say it like that. But as you mention youself, I don't really know how to implement this with playmaker..

I'm trying to just measure the velocity(of the drag) in one state, and add it to the object in the next state. But it does not measure velocity when I drag the object, only when it reacts with the physic engine.

I have attacted my scene if you got a minut to look at it.. I've been playing around with this problem for a couple of days now :(

EDIT:
It's like when I drag the object, it ignores all physics. I can move it through the walls too. If I find a solution to that problem, I think it can measure the velocity too.. maybe..

MODERATION EDIT : removed package. Make sure you don't include the playmaker dll when packing...
« Last Edit: February 20, 2012, 12:41:57 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #3 on: February 16, 2012, 03:39:55 AM »
Hi,

 I'll have a look over the week end ( sorry, a bit busy at the moment).

 bye,

 Jean

OleP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #4 on: February 16, 2012, 03:42:53 AM »
Hi,

 I'll have a look over the week end ( sorry, a bit busy at the moment).

 bye,

 Jean

Thank you.. :)!

OleP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #5 on: February 20, 2012, 01:22:36 AM »
MODERATION EDIT : removed package. Make sure you don't include the playmaker dll when packing...

Woops, sorry!
Should be excluded now..

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #6 on: February 20, 2012, 11:21:16 PM »
Hi,

 Indeed this is odd. I looked at your project and I can get some velocity if I really shake the object real fast. also, the velocity then decreases very slowly, tho the object is not moving at all...

 Can't make sense of all this just yet ( never used that before). Will see if I get some result.

 Unchecking "use gravity" does give more velocity... go figure...
also turned down sleep velocity to 0 in the physics settings and increase iteration to 20. but I am not sure it changes anything.

bye

Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #7 on: February 20, 2012, 11:27:37 PM »
Hi,

 me again. looking at the official help, I think velocity is not something to get but actually to set. This one very bad thing in the doc ( tho I think it's very good overall). you never know if a variable is meant to be accessed or set... typical example here again.

Also, I think the action should get the velocity OnFixedUpdate like in the help ( but that doesn't change anything neither so far).

 so I think you are better of to roll your own solution. It's not difficult, simply get the delta position and divide by the deltatime, this is your speed.

 Bye,

 Jean

OleP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #8 on: February 21, 2012, 02:38:17 AM »
Thanks for explaining that.. But I don't quite get what you want me to do?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #9 on: February 21, 2012, 03:25:56 AM »
Hi,

 ok, I'll work out an example. basically, you store the delta drag and delta time value during the drag and when drag is finish, you compute the velocity by dividing this delta drag by the delta time and done.

Bye,

 Jean


OleP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #10 on: February 21, 2012, 03:33:21 AM »
Hi,

 ok, I'll work out an example. basically, you store the delta drag and delta time value during the drag and when drag is finish, you compute the velocity by dividing this delta drag by the delta time and done.

Bye,

 Jean



An example would be priceless.. I think I need to see how it's done, before my brain will understand it properly..

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Add velocity to object based on drag velocity
« Reply #11 on: March 27, 2012, 08:29:51 AM »
Hi,

 ok, I have cracked the case finally, thanks for waiting :) I did not forgot!

http://hutonggames.com/playmakerforum/index.php?topic=1286.0

Very simple,
1 :have your object as a rigid body of course
2: create a fsm, and on the start state, put that action
3: check Attach to mass to true for your case. it will make your puck behave nicely
4: set the draggingPlaneTransform to the ground plane

 Now when you drag, it will drag on the ground ( it uses the up axis of the ground)

If you can't get it to work, I'll make the scene :)

 Bye,

 Jean