Giter Club home page Giter Club logo

adaptinggravityunity3d's Introduction

Adapting gravity for Unity3D

Discontinued, maybe KaimaChen/How-To could be another interesting reference for you.

Introduction

Think of games like super mario galaxy. Mario can jump from one planet to another and run on those small spheres without problems. Also in racing games the tracks are often not just on the ground. With this repository I want offer a small library to create exactly such gravity adaption possibilities.

Technical overview

To get the desired effect all objects that should adapt to gravity check for ground objects via ray-casts. If they find a ground object near them, they save the normal map of the surface and take the negative surface normal as the new gravity direction. A screenshot of the unity editor in which a cube is on a larger sphere. From the cube a green line is drawn in the current gravity direction

Usage

To use the library you have to make changes for every object that should be attracting as well as for every object that should be influenced by gravity. The introduction of adapting gravity can be accomplished by those few steps:

  1. Add the AdaptingGravity script to all objects that should attracted by adapting gravity. You can also start by only adding it to your player. You find the script in Deml/Physics/Gravity. If you are starting your project from scratch you can add the prefab player from Deml/Player/Prefabs/Player.
  2. Once the script is on the player you can tweak specific settings for it.
  3. The attracting object tags will define which tags should be considered to be attracting to the player.
  4. The gravity strength defines the strength the player will be attracted to objects. The acceleration is set in m/s². (Side note: The gravity strength of the earth would be 9.81 m/s², but in games you would normally use a greater strength)
  5. The gravity check distance defines the distance of the ray that will check of objects that are able to attract the object
  6. The ground check distance defines the distance for which an object will be seen as touching the ground. This could be relevant if you want to only be able to move with the player if it is touching the ground.
    A screenshot of unity3D that shows the parameters that can be changed through the editor
  7. If you want the player to perfectly rotate to the current gravity direction also add the script LockFallingOver to the player object. It can be found in AdaptingGravity/Scripts/Physics/Manipulation
  8. Add one of the tags you defined are valid for attracting objects (You defined them in step 2.1, if you didn't the standard value is only the tag "Ground") to all objects you want to be attracting to other objects.
  9. You can where the evaluation of ground objects should happen by adding handles to the object. You will find a button for that in the GravityHandler script.
    Add handles by pressing the button. Afterwards you can rotate and transform them the way you are used to
  10. With the weigted average toogle you can define if the gravity should be defined by the direction of the nearest object that is hit by a ray or by the average of all objects that are hit.
  11. You're set and ready to tweak the settings to your needs.

Licence

AdaptingGravity is released under the MIT Licence.

adaptinggravityunity3d's People

Contributors

johannesdeml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

belzecue elongame

adaptinggravityunity3d's Issues

Movement Issue

Hey! This is an awesome project. I figured I'd pull it into Unity 2017 and resolve any potential issues. Off the bat, the forward movement is jittery and I was just wondering if the movement was ever fluid in the original build

I started modifying the code and got it about a half second faster, but it seems there is about a 2 second delay between movements (not rotations). Wanted to check whether it ever was completely responsive :)

The calculations shouldn't be that intensive from what I"m looking at, however the player becomes more responsive when further away from the gravity object :/ May just need to update some functions for the movements and the normal detection etc... If you could let me know I'm going to see if I can get that fixed :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.