playMaker

Author Topic: Circular Gravity 2d  (Read 1718 times)

misterjuly

  • Sr. Member
  • ****
  • Posts: 357
Circular Gravity 2d
« on: December 06, 2020, 09:54:16 PM »
Hello,

I've got my character moving left and right and I want him to be able to walk around a circle (kinda like a planet). I would eventually like to have my character be able to jump from one planet to another (keeping in mind this is all 2d), sort of like Mario Galaxy. If I could have extremely detailed instructions on how to do this, that would be great, as I am not very good at this. Thanks!

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 824
Re: Circular Gravity 2d
« Reply #1 on: December 07, 2020, 08:56:25 AM »
I suggest trying Unity's Constraint components, mainly those dedicated to distance and rotation.
You will need to code your own gravity (lerp on the local vertical axis).

misterjuly

  • Sr. Member
  • ****
  • Posts: 357
Re: Circular Gravity 2d
« Reply #2 on: December 07, 2020, 03:33:38 PM »
Thanks for the reply. I don't see the Constraint Distance component. Also, do your instructions contain advice for jumping from planet to planet or just walking around it? If not, could you also explain that? Also, could you be more specific on how to do the coding part of it? I assume you mean doing it through playmaker, but I wasn't sure based on your comment. Thanks!

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 824
Re: Circular Gravity 2d
« Reply #3 on: December 08, 2020, 05:11:42 AM »
Ah sorry it's actually Position Constraint, so that in a local mode, it can be used to define a distance. I haven't tested anything like your case yet so I'm throwing ideas right now. Look At Constraint might be useful to to have your object's vertical axis always point in a specific direction.
You'll have to combine them and do tests because constraints can generate very weird effects that are hard to predict, but once you got the right combination it's absolutely rock solid.

misterjuly

  • Sr. Member
  • ****
  • Posts: 357
Re: Circular Gravity 2d
« Reply #4 on: December 08, 2020, 07:43:29 PM »
Ok thanks. I'm still a little confused to be honest. Is there a video link or something that you could share so that I have more detailed instructions. Keeping it in Playmaker would be preferable unless I could copy the code (but even then, playmaker would be nice). Thanks again for your help! I really appreciate it!

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 824
Re: Circular Gravity 2d
« Reply #5 on: December 09, 2020, 12:30:16 PM »
Honestly the constraints are fairly independent of Playmaker. Setting them properly is a big part of their use. They are automatic.
In Playmaker you will be managing the character's moves around the disc but that's it. The constraints are there to simulate a gravity that always points towards the center of the disc.
You must apply the constraint components to the character but also use the disc as a reference in the proper fields. Try the Look At one for starts. Making tests is the key, no time is wasted as it teaches you Unity empirically.

Adding 2D colliders, like on the disc, can be used to block the character from ever passing through the disc but I suppose this could also be done by fixing a vertical distance.
You can drag a component into a state in Playmaker's Graph View, it will open a window to set or get the component, so you can change the component's values as you see fit.

If you use this way of controlling Unity components, don't forget that you'll need to run the Linker Wizard (look it up on forums) before publishing your product.
Otherwise, look into how to code simple actions by using Unity's script API manual. The best way to do that is to generally copy a simple action, see how the code does what it does and then try to modify it slightly to create a new action that can modify Constraint components' values.