playMaker

Author Topic: Movement/Force proportional to time key is pressed  (Read 2099 times)

Nazca

  • Playmaker Newbie
  • *
  • Posts: 4
Movement/Force proportional to time key is pressed
« on: July 04, 2012, 09:52:38 AM »
Hi everyone, this is Francesco writing from Italy.

I'm a newbie and this is my first post, so please be kind!  :)

I run across a problem with playmaker and, after a lot of pointless attempts in the past weeks, I realized I might need some help from the experts.

Here is the problem:

Just like a cilinder-shaped vertical pin popping up and hitting a marble, I'm trying to have a similar game object "jump" on its Y axis, hit another game object (a sphere with rigidbody component attached) and then revert to its original position.

I'd like to have the "pin" movement and the force applied to it to be proportional to the length the user keep a certain key pressed, until a max time value (let's say 2 seconds).

This would allow me to simulate a slight touch as opposed to a strong hit, and all the gradient inbetween.

I tried to split the problem in various bits (which might as well be placed in different fsm, where needed)

So far, I have been doing the following:

To get the time length a key is pressed:

1: get key down
2: get time info (in current state) and store value to a float variable "time" (clamped to the max value of 2)
3: get key up

..so far so good..

then comes the part where I have to convert the float value (which range from 0 to 2) to something usable for the movement/force applied.

This is the part where I am messing up badly :(

Here's the logic I've been following:

4: sample curve (here I'm sampling the value of "time" float variable over a custom curve and store the result in another float variable "power", in order to turn it into somehing more usable for movement/force)
5: add force (using the "power" varaible over the y axis)

Well, the pin moves but quite oddly, even after a lot of tweak of the curve.

I'm unexperienced enough to believe that the whole problem can be solved in a more solid and reliable way, but I can't figure out how. (maybe using spring/configurable joints?)

Is there anybody who can put me on the right track?

Appreciation to anyone who will help and congrats to the developer of this great tool who made a noob like me quite able to prototype a game!  ;D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Movement/Force proportional to time key is pressed
« Reply #1 on: July 05, 2012, 03:31:03 AM »
Hi,

 you seem to be on the right path. I guess it's more a problem of something wrongly  set up in your fsm.

 Try to cut down the problem.

1: control the power value manually, set it up to show up in the inspector and modify it yourself manually, if that works then the logic of adding forces based on power is fine, and you know it's the power value control that is wrong,

2: watch the power value based on the input and if it acts accordingly

3: watch the relation between the curve input and output, this might be where the problem is. First do it without any curve, a straight multiplication of the initial force and power based on the user input, then when that works try to insert a curve control on that.

 Bye,

 Jean