Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

2D Faux gravity. Help

Discussion in 'Scripting' started by mrhagge, Oct 13, 2018.

  1. mrhagge

    mrhagge

    Joined:
    Nov 22, 2017
    Posts:
    4
    Hello, I'm wanting to make a script for walking on planets in 2d with gravity like it. Example http://www.adiosgame.com/

    Please help me on how I could achieve this in c#.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    2,890
    At a glance there's a few things going on:

    1. gravity is angled for each actor to point to a central point (which planet they're on)

    2. actors rotate to align to the ground beneath them

    3. the camera is rotated to follow a given actor

    You can do #1 by taking the difference between the planet and the actor and using that vector as the basis for gravity (normalize it first, then multiply by the desired gravity)

    You can do #2 by using rotating your character so it aligns with the delta calculated in step #1 above.

    You can achieve #3 trivially by parenting the camera to whatever actor is the main player actor.

    That should get you started anyway. Let us know how it goes!