Add Force Not Decelarating Enough

Hi!
I’ve been messing around with Add Force and was trying to make an oscillator that moved left to right using physics. (Details)

I am following this equation

to calculate a multiplier for the forward vector of the actor.

Then I am calling Add Force at every tick using the function above.

The issue is that the actor instead of oscillating, accelerates, decelerates, stops then repeats the cycle. I am really confused because I am certain I got the equations right and I tried implementing this by changing the velocity according to the equations and that works perfectly.
What is going on here?

Hello:

I’m no math genius, however:

0
0
0
1
1
2
3
3
4
4
4
3
3
2
1
1
0
0
0

Anytime the function hits “0” or “4”, basically the PEAK and the TROUGH, there’s going to be a “stop”; this is, of course, how interpolation works.

But this is assuming my assumption is correct, and that it works that way.

If I were you, just to make sure, I would add a print string to the output velocity/force/impulse value to see how it’s behaving.

Hey, the thing is that the function follows the path of a cosine wave which behaves like the image below.
cosinewave

So the Peak is positive while the Trough is negative. This is confirmed by the logs of the function which go like this:

This means that, at least according to theory, the object should follow the path I mentioned above. I believe the issues lie with Add Force, or at least my use of it. Is there something I am missing, especially with how I am supposed to handle variable forces? Cause all the examples I have seen of it have used a constant force instead of a changing one like I am doing here.

Yes, the numbers follow an almost identical trend to my numerical example.

Starting with your “-7046” value", the differences (delta values) are:

(+500 → +700 → +1000 → +1300 → +1400 → +1500 → +1500 → +1500 → +1300 → +1200 → etc.)

You get the point, where the BOLD is the TROUGH/PEAK of the waveform cycle.

And any time the values approach a PEAK and TROUGH there is going to be a TRMENDOUS amount of deceleration, so much so, that it can appear to be “0” or not moving. So, it’s likely moving, but VERY slowly.

I generally avoid using these functions for this reason, and create my own.

That said, I would, for now, forgo the function, and input simple integer values into the FORCE INPUT PINS to see how the node/function behaves.

So you are saying because of the big deltas during the Peak and Trough, there isn’t an accurate motion?
Even so, I tried what you suggested and now just apply the normalized forward vector * 500 with the sign changing as we go. Now the motion is better but it still isn’t a perfect oscillation as with every loop, the actor goes slightly to the left.

I see where the confusion is:

No, I mean, the delta isn’t really changing at the PEAK or TROUGH (+1500). It’s tangential.

Anyway:

You really need to assign PRINT STRINGS to the outputs to tell you what’s going on numerically.

To the force, the location and the velocity?

ALL!

Yes.

Ok, I logged the Location, Velocity and Force of the actor and they show that what I say happen. For some reason the Location at the Peak and Trough shift with each loop.

Output Log.txt (453.7 KB)

This is VERY hard to read.

Can you post a video and have the values print on the screen during gameplay?

Here you go:
2024-03-02 11-52-04.mkv (21.0 MB)

In terms of the general shape of the wave, it is correct.

Your issue, if I understand correctly, is that the Y LOCATION VALUE, over time, starts to become more and more positive.

There’s something off in the math or these wave functions do not operate the way you expect them to do.

Try using the function here:

But in the video, I am not using the wave functions. If you look at the Force I am applying, it’s just a constant vector that changes its direction. So why is it not working correctly? I am not trying to implement a bobbing feature, I want to use Add Force for something else and I decided to make something I thought was simple. But I see that it is not behaving like it’s supposed to at all.

It’s behaving the way it’s supposed to, but you’re missing something.

You have to be constructive not destructive when handling problems. The attitude, “this isn’t working” should actually be, “how can we get this to work?”

I’m trying to help you figure that out.

That said, again, I would suggest breaking down each component of your code, PRINT STRING it, and see how it behaves.

You’re using COS instead of SIN, so that could be the issue. Unsure though.

There also may be a better way to implement whatever you’re trying to implement, without the oscillatory force function, so you might want to look into that. You could be going at this the hard way.

Yeah sorry for that. Just frustrated because I have a funny feeling that Add Force isn’t accurate enough or wasn’t designed for this and I am wasting my time.

I have continued to work at it and printed each step of both the cosine wave and the function adding the force but I still couldn’t see something out of place. My guess is that due to the nature of this movement, the errors from the floats, the integrations and the physics below accumulate and prevent the oscillation from happening perfectly.

What I am trying to implement is a system where there is a force applied to the player constantly opposing his movement. That force should change according to the player’s speed. I saw that I could also use linear damping for this. Not only that, but I also saw that I could store my own forces and then integrate them each step to calculate a speed delta, using that to change my actor’s speed.

The reason this has confused me so much is that in theory, it should work perfectly. I have worked extensively with these equations for the oscillation before and the force follows the wave it should take perfectly. Unfortunately, the speed seems to start going off course because it’s slowly shifting from the normal range it should have (think of taking a sin wave and slightly moving everything up), leading to the location also being thrown off. That’s why I am being led to believe that Add Force isn’t accurate enough for this

1 Like

Thanks, I genuinely appreciate it.

So:

@SupportiveEntity , @ClockworkOcean, @Everynone:

I promise NOT to make a habit of tagging you, however, if either of you has an idea on how to implement @arskon03 's desired effect, that’d be greatly appreciated. I usually don’t handle physics, but I’m certain the fix is easy, just out of my scope.

@baobao4435 , this post may be of interest to you. You’re a voracious learner. (Again, I won’t make a habit out of tagging; it’s annoying.)

2 Likes

What’s supplying the time variable?

Right now I am incrementing it each tick by delta time and then supplying it to the cosine wave

1 Like

Just chcking it’s cumulative :wink:

1 Like

I found this,hope it could help.