Jump to content
Einlander

Simple Per Entity No Gravity

Recommended Posts

I was messing around one day and wanted to have certain objects be weightless. So I came up with this simple code.

 

function Script:UpdatePhysics()
self.entity:AddForce(0,self.entity:GetMass()*-world:GetGravity().y,0,true)
end

 

Just wanted to share it. You can can control the amount of weightlessness by controlling the amount (%) of gravity used in the calcualtion

Share this post


Link to post

A small modification. You can now declare the percentage of gravity affecting the object. There are no limits placed on the percentage . So negative numbers will make it float up and numbers > 100 make them super heavy. Beware of large numbers because they will clip through other objects.

 

Script.Gravity = 100  --float "Gravity Precent"
function Script:UpdatePhysics()
self.entity:AddForce(0,(self.entity:GetMass()*-world:GetGravity().y)*(((100-self.Gravity)/100)) ,0,true)
end

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...