Jump to content

Odd force result?


Andy Gilbert
 Share

Recommended Posts

Ok, ive been pulling my hauir out at an issue and so to test i have gone back and created the most basic script and i still get the issue.

 

If i have a bodybox, and i slowly increase an "up" force in global space, (so it doesnt matter what rotation it is, the force is always up) the box will slowly lift up and then accelerate upwards, quite rapidly?

 

Well im not increasing more force, im using "setforce", not "addforce".

 

I just dont get it, it lifts up very slowly, then after a short while will start to accelerate and then "shoot" off ub into oblivion?

 

And then it acts as if the "higher" the object the less force is needed to keep it up, until if high enough a force of 0 WONT left the object fall back down???

 

Edit:

Ive done even more playing and found it actually un usable and wonder how ive actually managed to use it in the past, i cant undestand whats going on??

 

Although these are arbitrary values.

 

I can Increase my up force by 0.5 i can get the object to lift off slowly at 65.

 

It will then slowly start to rise but accelerating, if i decrease to a point where the object starts just start to fall its MUCH lower that 65, in fact if i lower it to say 40 it will still accerlate up, (even though it only just lifted off the ground at 65) if i ACTUALLY manage to get to stop and start to fall slowly, this value is now much lower, around 15 - 25? When before it was 65 and it appears that the higher i go, the LESS force is needed to make the body move upwards, to a point where i can get it to return to the ground unless an OPPOSITE force is applied, almost like gravity has vanaished.

 

Thanks

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

Well if not opposed. A constant force will cause an object to accelerate continuously and keep getting faster.

 

Now you may say that gravity is opposing.. well yes it is but both forces are constant so you still have a constant force in 1 direction.

 

Basically if your upward force is stronger than the gravity then this will happen and the body will keep getting faster.

 

Therefore, it is acting as it should. If such an imaginary force could exist in real life the exact same thing would happen.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

But why does this force thats needed to make the object "rise" vary with height???

 

I understand that it will keep accelerating if greater than gravity, but why if the value to make the object rise against gravity is 65 from the ground, does it change to 20 when higher, or its only 5 when even higher?

 

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

Here is a video showing what im experiencing. You can see the code in background, theres nothng more to it.

 

Note: You will need to watch full screen to see the value

 

 

So the value i labled to "keep an eye on" is simply a value increased with the "up" key, by 0.5 increments.

 

But what you will notice is it takes 80 to lift the box off the ground, then near the end only a value of around 25/30 is needed to make excert the object up? Whats changed?

 

Edit: I have raised the camera higher and it appears as though the object and force acts correctly untill it rises higher than the camera, then it starts going daft? Why would this be?

 

Here is another video to show this:

 

Similer Video as the other, except the camera is higher and the body seems to react fine whilst under the camera. To lift the object off the ground its around 70, if i lower below 70 it starts to drop, if i increase above 70 it starts to rise.

But when the object is above the camera the force value to do the above is about 20??

 

 

 

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

Here is the code for the above. (Lua)

 

require("Scripts/constants/engine_const.lua")
RegisterAbstractPath("")
Graphics(800,600)
fw = CreateFramework()
camera = fw.main.camera
camera:SetPosition(Vec3(0,10,10))
scene = LoadScene("abstract::ADDSCENE.sbx")
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
HideMouse(1)
camrotation = Vec3(0)
--box
box = CreateBodyBox(1,1,1)
box:SetPosition(Vec3(0,7,0))
box:SetMass(1)
box:SetCollisionType(1)
boxv = CreateCube()
boxv:SetParent(box)
box:SetFriction(0,0)
box:SetDamping(50,1)
Collisions(1,1,1)
DebugPhysics(1)
temp_up = 0
while KeyHit(KEY_ESCAPE)==0 do

camera:Point(box,0,1,1)
--move camera
move = KeyDown(KEY_W) - KeyDown(KEY_S)
strafe = KeyDown(KEY_D) - KeyDown(KEY_A)
camera:Move(Vec3(strafe/2,0,move/2),1)
--body inputs
pitch = Curve(KeyDown(KEY_UP) - KeyDown(KEY_DOWN),forward,1)
roll = Curve(KeyDown(KEY_LEFT) - KeyDown(KEY_RIGHT),roll,1)
yaw = KeyDown(KEY_Z) - KeyDown(KEY_X)

if KeyDown(KEY_2) == 1 then
 temp_up = temp_up + 0.5
end
if KeyDown(KEY_1) == 1 then
 temp_up = temp_up - 0.5
end
upvec = TFormVector(Vec3(0,temp_up,0),nil,box)

torque = Vec3(pitch*80,0,roll*80)
force = upvec
box:SetForce(force)
box:SetTorque(torque)

fw:Update()
fw:Render()
SetBlend(1)
 DrawText("KEEP AN EYE ON THIS VALUE: "..temp_up,10,20)
 DrawText("BOX UP FORCE: "..upvec.y,10,60)
SetBlend(0)
Flip(0)
end

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

Gravity is a constant force of 9.8 meters per second squared. Gravity causes objects to accelerate. If you want a constant speed use CalcBodyVelocity to figure out the required force.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Yes, but your not understanding the problem??

 

If you watch the 2nd video, it shows that when the object is below the camera, the force to keep the object bobbing up and down is about 80, but when above the camera the force is only about 20? Yet i have changed nothing, this is causing massive issues with forces?

 

How can the force to appose gravity be one value when its below the camera and a completly different value when above the camera?

 

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

Ok, so wen you say somthing funny is going on there, is that somthing funny thats needs to be fixed by me in my code or a bug?

 

If so how do i make it not do this?

 

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

ahh right, ok.

 

Any chance of it being looked at? I have spent hours and hours trying to get my code to work until i finally figured this out, and now of course im stuck without being able to do anything.

 

Thanks

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

I couldn't get airplanes to fly with the default gravity on, so I put everything to 0 gravity and added my own gravity/uplift to each object. That also allows you to have planetary spherical gravity, when you put a pivot in the center of the planet, and align your forces to that.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

I know what's going on...

 

Since your framerate is below 60, the physics are being updated multiple times per frame. After an update, the force is reset to zero.

 

If your framerate is 15, the force gets carried out on the first physics update, but does not on the next three that occur before the world update function finishes.

 

It's better to call any physical functions like this in an entity or world physics update function, so it always gets called before each physics update occurs.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...