Jump to content

[HELP] Error calculating default gravity


rubend10s

Recommended Posts

How can I get to simulate default gravity? this is my code


fps = 1000/36 -- 36 frames per 1000 miliseconds default value server
gravity = 0.008 -- global gravity of the server

function gravity_without_camera( timeSlice )

	local vehicle = getPedOccupiedVehicle( getLocalPlayer() )
	local speedX, speedY, speedZ = getElementVelocity( vehicle )

	local new_gravity = gravity * ( timeSlice / fps )
	
	setElementVelocity ( vehicle, speedX, speedY, speedZ - new_gravity )
end

function set_new_gravity()
	local vehicle = getPedOccupiedVehicle( getLocalPlayer() )
    if not toggleOff then
	    removeEventHandler("onClientPreRender",getRootElement(),gravity_without_camera)
		outputChatBox ( "script disabled" )
		setVehicleGravity( vehicle, 0, 0, -1 )
		toggleOff = true
	else
	    addEventHandler("onClientPreRender",getRootElement(),gravity_without_camera)
		outputChatBox ( "script enabled" )
		setVehicleGravity( vehicle, 0, 0, 0 )
		toggleOff = false
	end
end

bindKey ( "m","down", set_new_gravity)


the new gravity is a little more powerful than the default gravity
idk why

Edited by rubend10s
Link to comment
  • Moderators
19 hours ago, rubend10s said:

the new gravity is a little more powerful than the default gravity
idk why

You might be able to test that.

Initial

Put yourself or the vehicle you want to test in the air. Gravity to 0. Speed to 0.

 

Start

Write down the velocity for every frame.

Set the default gravity and test how the speed is changing for the first few frames.

 

Note: keep in mind that vehicles also have their own mass.

Edited by IIYAMA
Link to comment
5 hours ago, IIYAMA said:

You might be able to test that.

Initial

Put yourself or the vehicle you want to test in the air. Gravity to 0. Speed to 0.

 

Start

Write down the velocity for every frame.

Set the default gravity and test how the speed is changing for the first few frames.

 

Note: keep in mind that vehicles also have their own mass.

oh that's a good way, I did something similar but I didn't write it down, I just looked at them haha

I managed to approximate gravity quite a bit by changing the fps value with

fps = 1000/50

it is not exactly the same but it approximates

at least it's a good way to avoid the annoying camera

 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...