Page 1 of 1

[Mod] gravitysim

PostPosted: Sun Jul 24, 2016 15:56
by Gundul
Description: This mod adds gravity simulation to your world. (not realistic though). It makes the gravity decrease the higher your avatar climbs.
And the higher you climb the higher you can jump.

Depends: nothing

License: nothing, free of everything, do what ever you want with it

No warranties, no garanties. If you run this on your server and your world says good bye do not blame me




I made this for my server, because player there building a space station and I thought it would be nice to have some
low gravity and moonlike jumping. Maybe some people find that also useful. Play around with the values so it suit the needs of your world.


Installation:

- create a new folder "gravitysim" in your mods directory.
- go in that folder and create a new text document "init.lua"
- copy below code to the document and save.
- start Minetest and activate gravitysim in your world


Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
--gravitysim   made by Gundul no copyright nothing, do what you want with it
--
-- do not expect realism here. This is just for fun. So try out any values you like
-- and which suit your needs :)
--
-- have fun



local timer = 0
local checktime = 5 -- postion check intervall
local gravity = 1 -- standard on earth 9,81 m/s*s on sea level that is equal with 1 in Minetest game

minetest.register_globalstep(function(dtime)
   
   timer = timer + dtime;
   if timer >= checktime then
   
     -- check all player altitudes and set new gravity
   
    
    
   local players = minetest.get_connected_players();
      
      
      for _,player in pairs(players) do
         local pos = player:getpos(); -- feet position
         local y=pos.y;               -- we only need the y ccordinate
         
         
         
        if y ~= nil then
          local newgrav=1;
          local newjump=1;
         
         
               if y >= 0 then
         
              newgrav = gravity - (y/1500);    -- going up in the sky just try out some values to suit your needs
              newjump = 1 + y/125,             -- jumping calculation
              
              player:set_physics_override({gravity = newgrav,jump = newjump });
              
          else
            
            -- commented out because if cannot even jump one node high its pretty useless to jump at all :)
            
             -- newgrav = gravity - (y/32000);    -- going to the center of earth
             -- newjump = 1 + y/10000             -- jumping should get lower the deeper you are
              
              
             -- player:set_physics_override({gravity = newgrav,jump = newjump });
              
          end
         
         
         
         
                -- minetest.chat_send_all("I come and get your y position :) y-pos = ".. y .. " newgravity is : ".. newgrav) -- commend this out for ingame debug
        else
         
         
        --minetest.chat_send_all("something went wrong") -- commend this out for ingame debug
       
        end
      end
      
   
   
   timer =0
   
   end
end)

Re: [Mod] gravitysim

PostPosted: Sun Jul 24, 2016 16:33
by DS-minetest
nice
but isnt on earth the placefactor g=9,81m/s² and not m*s²

Re: [Mod] gravitysim

PostPosted: Sun Jul 24, 2016 18:20
by Gundul
DS-minetest wrote:nice
but isnt on earth the placefactor g=9,81m/s² and not m*s²


oh embarassing, I have to go back to school :D

thanks

Re: [Mod] gravitysim

PostPosted: Sun Jul 24, 2016 20:29
by Sirmentio
This sounds cool! I can't wait to try this myself!

Re: [Mod] gravitysim

PostPosted: Mon Jul 25, 2016 09:44
by azekill_DIABLO
+1 when we do a minetest parody of interstellar?

Re: [Mod] gravitysim

PostPosted: Tue Aug 30, 2016 08:49
by ABJ
Accidental necropost, mod delete please.