playMaker

Author Topic: Set Velocity + Add Force?  (Read 1376 times)

Thore

  • Sr. Member
  • ****
  • Posts: 480
Set Velocity + Add Force?
« on: August 16, 2019, 10:23:41 PM »
Does anyone have an idea of how Set Velocity and Add Force could be combined? Right now, Set Velocity seems to overwrite all forces (including physics) and thus cancel Add Force, too, unless it's added in another direction.

This is a bit of a problem: I want to add some sideways force to a jump, but it doesn't work, because the movement is done with Set Velocity. Temporarily disabling the movement, or having it go to an empty state felt like a hack and didn't work reliably.

Does anyone know how to do this?


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Set Velocity + Add Force?
« Reply #1 on: August 18, 2019, 08:36:08 AM »
Hi.
I recently did something similar by increasing the velocity (gradually with a tween)

You can try with the beta tween actions if you like :
https://hutonggames.fogbugz.com/default.asp?W1714

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Set Velocity + Add Force?
« Reply #2 on: August 18, 2019, 01:39:43 PM »
I think that would not alleviate the problem. I used the Float Tween for a nice smooth acceleration and deceleration, in a fairly elaborate setup (which I now discarded).

The way the Set Velocity action is written, it always seems to hard-overwrite the velocity no matter what. In order to do something like a dash, you need to suspend the Set Velocity, so that the Add Force can work on top of the current velocity (which is maintained, unless changed by the physics).

It's technically correct that when the input is zero, it would also set the velocity to zero. But that can feel weird, because zero can also be interpreted as "no input", rather than "stop movement". I already once encountered the problem with physics objects (see here also with samples), hence I made a version with the neutral setting, but that didn't solve my current problem.

I now wound up writing my own platform movement action, with good (and simple) acceleration and deceleration, a momentum setting and bool that allows me to suspend the entire thing. I also built a coroutine into it that switches the suspension off after a specified amount of time. So, e.g. that when I want to dash, switch the suspension on for a few frames, and it switches it off automatically.

But the kicker is this: somehow my action doesn't need my suspension setup, as I found out moments ago. Somehow, in my action, it does Set Velocity, but Add Force is not canceled. Don't know why. For now, it's sorcery but I am happy with the outcome because that makes things a lot easier. ;)