Jump to content

How Do You Change World Gravity?


mdgunn
 Share

Recommended Posts

I want to change gravity for the world (SetGravity(x,y,x)) by triggering it from an object entity but how do I access the world object created in Main.lua? Or is there a different way to do this?

 

Can you add functions to Main.lua that you then call from other entities?

 

I'm confused about the change to Main.lua and how it compares to how things used to be with App.lua.

Is there a post somewhere that went through the change to Main.lua?

 

Thanks,

 

Michael Gunn

Link to comment
Share on other sites

Or you could go to your scene tab, select "root" and navigate to gravity, the deafault value is 25 but here you can only change the y value of the gravity

 

But that would not allow be triggering it in game would it (unless I'm missing what you mean)?

Link to comment
Share on other sites

@Genebris I went with using a global.

 

Personally GLOBALS make me a bit scared. I'd prefer to call a function but I still undertand how you call a function on Main.lua from an entity (or if you can). Anyone know if you can, of are you supposed to go back to the App.lua way to do it?

 

If anyone stumbles accross this later this is how I got gravity change trigger working

 

I added this into Main.lua

 

--Handle Y Gravity change
if changeYGravity~=nil then
--System:Print("changegravity = "..tostring(changeYGravity))
world:SetGravity(0,changeYGravity,0)
changeYGravity = nil
end 	

 

And I created a script called TriggerGravityChange.lua like this (modified from map change one - you may need to change it to your needs).

 

 

--[[
This script will act as a trigger to change the gravity.
This is currently triggered by a collision but you may want to have it triggered by some other means.
]]--
-- positive number for Y gravity are UP!
Script.YGravity=10--int "Y Gravity"
Script.gravityChanged = false
function Script:Start()
self.enabled=true
end
function Script:Collision(entity, position, normal, speed)
if self.gravityChanged~= true then
--System:Print("Change Gravity - new value = "..self.YGravity)
 changeYGravity=self.YGravity
self.gravityChanged= true
end
end
function Script:Enable()--in
if self.enabled==false then
self.enabled=true
self:CallOutputs("Enable")
end
end
function Script:Disable()--in
if self.enabled then
self.enabled=false
self:CallOutputs("Disable")
end
end

Link to comment
Share on other sites

 

Thanks for the warning macklebee. Luckily I am triggering in game and I seem to have got it working OK, though as I mentioned I went with globals though I'd prefer to call a function (on Main.lua) but I think I don't have clear understanding of if I can do this on Main.lua. Anyway working for now.

 

Thanks,

 

Michael

Link to comment
Share on other sites

You can call a function inside App.lua from any other script just like you use variables:

App:ChangeGravity(value)

 

He is not using the old App.lua format but the new Main.lua. But yes he could essentially perform the same by just placing a function inside the Main.lua prior to the main loop.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

He is not using the old App.lua format but the new Main.lua. But yes he could essentially perform the same by just placing a function inside the Main.lua prior to the main loop.

 

This is the bit I don't yet understand so can someone please supply the syntax for what the function signature looks like when in Main.lua and also the specific syntax to call it from an entity.

 

 

Thanks,

 

Michael

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...