Search Unity

Circular Gravity Force

Discussion in 'Assets and Asset Store' started by LaneMax, Dec 13, 2013.

  1. Blackghost

    Blackghost

    Joined:
    Oct 2, 2012
    Posts:
    103
    Hello. Great asset!. I was wondering how i could increase/ decrease force power, and or change size, via button press/hold, at run-time?
     
  2. Blackghost

    Blackghost

    Joined:
    Oct 2, 2012
    Posts:
    103
    Also, the ability to cycle through shape, force type and force modes during run time would be awesome. Via button inputs, of course. Dynamic gravitational changes, via button holds and inputs would be appreciated. It would add a lot to this already wonderful asset. Thanks again!
     
  3. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Yep works well, also here is a newer trailer with some 2D stuff in it, cheers!

     
  4. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey Blackghost try playing with the AxisControls, and KeyControls in the package. You can ether find them in the Tools->CGF->Contols or Right Click on the CGF script and they should appear.

    Example:
    Untitled.png

    Also I show how to use them in some of these video tutorial:




    And lastly if you wanna skip that all together here is a quick code example if you want to write a script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. using CircularGravityForce;
    5.  
    6. public class CGF_Control : MonoBehaviour
    7. {
    8.     public CGF cgf;
    9.  
    10.     // Use this for initialization
    11.     void Start()
    12.     {
    13.  
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         if(Input.GetKey(KeyCode.Space))
    20.         {
    21.             cgf.Size = 10f;
    22.         }
    23.         else
    24.         {
    25.             cgf.Size = 0f;
    26.         }
    27.     }
    28. }
    29.  

    Let me know if this helps

    Cheers!
     
  5. Blackghost

    Blackghost

    Joined:
    Oct 2, 2012
    Posts:
    103
    Thank you, kind sir. Just one more question. How would I multiply an increase in the force, and or size, by holding down a button?
     
  6. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    For something like that you'll probably have to get you hands dirty and wright a script... well you caught me in a good mood =P

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. using CircularGravityForce;
    5.  
    6. public class CGF_Control : MonoBehaviour
    7. {
    8.     //CGF Used
    9.     public CGF cgf;
    10.  
    11.     //Key
    12.     public KeyCode keySize = KeyCode.Space;
    13.     public KeyCode keyForcePower = KeyCode.LeftControl;
    14.  
    15.     //Multiplier
    16.     public float sizeMulti = 2f;
    17.     public float startForceMulti = 2f;
    18.  
    19.     //Saved start size and forcepower
    20.     private float startSize;
    21.     private float startForcePower;
    22.  
    23.     // Use this for initialization
    24.     void Start()
    25.     {
    26.         startSize = cgf.Size;
    27.         startForcePower = cgf.ForcePower;
    28.     }
    29.  
    30.     // Update is called once per frame
    31.     void Update()
    32.     {
    33.         //Size
    34.         if (Input.GetKey(keySize))
    35.             cgf.Size = startSize * sizeMulti;
    36.         else
    37.             cgf.Size = startSize;
    38.  
    39.         //ForcePower
    40.         if (Input.GetKey(keyForcePower))
    41.             cgf.ForcePower = startForcePower * startForceMulti;
    42.         else
    43.             cgf.ForcePower = startForcePower;
    44.     }
    45. }
    Cheers!
     
  7. Blackghost

    Blackghost

    Joined:
    Oct 2, 2012
    Posts:
    103
    Lol. Thank you again sir. Im trying to get my head around coding, and am able to understand the pieces of code, more. It is exciting to learn a new language!
     
  8. Blackghost

    Blackghost

    Joined:
    Oct 2, 2012
    Posts:
    103
    What is the difference between GetKey and GetKeyDown? I also though about something really cool, while reading these functions. In reading the GetKeyUp function, I was thinking about how CGF can utilize this. For instance, while holding down a key, I can steadily increase the distance of the raycasting for the size, and or force if the option is there. Then, upon releasing the key, using the GetKeyUp function, the force is activated. Almost like sending a probe and designating when and where you want to activate it.
     
  9. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Cool! Yeah it gets pretty fun! GetKey gets fired on Update vs GetKeyDown or GetKeyUp only gets fired once every time its pressed or released. Also I've found that 'Rewired' https://www.assetstore.unity3d.com/en/#!/content/21676 is an awesome asset with my content if you havent checked it out, although you'd have to jump into some more code ;)
     
  10. Blackghost

    Blackghost

    Joined:
    Oct 2, 2012
    Posts:
    103
    Great!, my friend. Maybe you would consider implementing these functions into CGF in the near future. That would be totality awesome!!
     
  11. etiosa obasuyi

    etiosa obasuyi

    Joined:
    Mar 5, 2016
    Posts:
    3
    Hi LaneMax, I recently bought your circular gravity asset, which is great so far. I am problem with the Hover tutorial. After I created the CGF and Hover trigger. Then I press Play, my object is moving forward. I don't understand why its behaving that way. I unchecked gravity, and the object hover and it didn't move . Can you help with this, Thank you. You mentioned that make character to walk around the planet is hard. Do you have any example beside the car?
     
  12. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey etiosa is this the tutorial you followed?



    Also could you send me a screenshot of your setup?
     
  13. etiosa obasuyi

    etiosa obasuyi

    Joined:
    Mar 5, 2016
    Posts:
    3
    Yes, I followed this tutorial. If the hover and cgi force doesn't aligned together would it cause some problem?
     
  14. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    I dont think so, can you send me a screenshot of your setup?
     
  15. etiosa obasuyi

    etiosa obasuyi

    Joined:
    Mar 5, 2016
    Posts:
    3
    Is working now Lane. Is there a way for me to set the hover speed low when the object is dropping down? Can you also tell me where the Gravitational force is located in your code. I will like to know if its possible to have the car or character walk about a box or/and capsule object.
     
  16. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    169
    Hi, I'm interested in buying your asset, but worried that it won't play well with my other physics-based assets. For example, I have vehicles with multiple colliders on them, under separate child objects, but just ONE rigid-body used for the main physics controls. I purchased a similar asset to yours in the past (but not as nice and polished as this looks) and it had a problem where the forces would be multiplied for each collider present in the game object.

    Have you checked for a similar issue with your package? I noticed in the demo videos that they are all very simple physics objects. I'm hoping you can test a gameobject that has 1 rigid body and multiple children compound colliders to see if this problem exists in this package also.

    Sorry... Just want to be sure before I make another purchase. Thanks!
     
  17. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    169
    Just to clarify a little more. If I use acceleration force on a gameobject, will the force be multiplied by the number of colliders present in the gameobject? That's the problem I'm trying to fix and I can't seem to find a way with my current solution.
     
  18. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey HakJak,

    Wow yeah thats pretty bad, colliders shouldnt have to do anything with the forces applied, only the rigidbodys. I'm pretty sure you should be fine, my asset only app physics to rigidbodys, and not colliders. Also one other nice fact is, if by chance you do have have multiple rigidbodys you can easily filter them out. Feel free to ping me if you have any other questions.

    Cheers!
     
    HakJak likes this.
  19. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey etiosa,

    You might have some luck with adding some drag on your hovercraft rigidbody, for the code check under 'CircularGravityForce Package->Scrips->CircularGravityForce->CGF.cs' and look for ApplyForce under line:909

    Cheers!
     
  20. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Hello LaneMax I recently bought your CGF package and I am just testing it, I am wish to make 3D FPS Battlezone(Hovertank)/Freespace,Wing Commander/Star Trek Bridge Commander(Space Fighter, Space Capital Ship) PC game, the thing is I was testing your FPCS Asset and I can't seem to get the charector to walk around the planet, even with me using the align control, Do I need to add extra code to the FPSC charetcor? Also it doesn't seem to respond to WASD control, the mouse works OK but the FPSC just seems to move all the time and WASD just moves its direction, it doesn't come to an automatic stop when the controls are not touched Please reply thank you
     
  21. mdotstrange

    mdotstrange

    Joined:
    Sep 23, 2013
    Posts:
    213
    Just upgraded to the newest version from 3.2- have been using Circular gravity force for about a year pretty comfortable with it-

    So with the new version all the circular gravity force scripts from the previous version are not found- so have to replace them on each object-

    I try to add the circular gravity force script component like I did with the previous version- no circular gravity force scripts found- ok- so its called CGF now let me look for that component to add- ok now there's all these-



    Which one to use? I don't know- I couldn't find any docs- is there a manual somewhere?

    What is the easiest way to move from 3.2 to 4? Thx
     
  22. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey mdotstrange,

    Yeah there is quite a big upgrade from 3.2 to 4. If you wanting to just add the cgf component click Add Component and without searching click on the Physics category and Circular Gravity Force will be listed, also if you want the 2D version its under the Physics 2D category

    1.png

    Also the quickest way to create CGF is through the toolbar.

    2.png

    Let me know if this helps.

    Cheers!
     
  23. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey Vampyr,

    Yeah you will have to make a your own FPS control that works with planets, I would suggest modding the Unity Standard Asset FPS Rigidbody script.
     
  24. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Oh I see and well its a pity but well would Sebastian Lague's FPS controller work then?
    [Unity Tutorial] First Person Controller: Spherical Worlds

    Unity Tutorial: Faux Gravity (walk on planets)


    And pity there isn't like a friendly or enemy A.I or even a standard A.I that would be able to turn friendly or enemy in level that can walk around planets and get in and out of vehicles and use them can this be used with UFPS ? As I wish to make my game multiplaer
     
    Last edited: Apr 19, 2016
  25. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    In theory if its a FPS Rigidbody Controller this will work but I've found when trying to forcefully moving rigidbodys, even if its using rigidbody.moveposition, things start to look pretty hacky because you interrupt Unity's physics from doing what is supposed to be doing. The best way to do this is to try to make the character/AI only controlled by the Unity's physics commands, which is A LOT of work, but in the end you get some of the coolest effects, example below:

     
  26. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Well from the example you have just shown me it does look like A LOT of work I did get a fairly rudimentary friendly and enemy A.I to work using Sebastien's 1st Person controller example and a simple A. to work but need to be able to get them into a vehicle namely a hovertank or a fighter bomber aircraft possibly some main base defense big autocannon guns.

    I was told to make the A.I hunt efficiently on a sphere you had to Get the direction of the enemy and its target, find a point some small distance of that line then fire ray through centre of that point point through the centre of the planet and then make it a ray point through the section of the ray and the ground Actually I think I got it from ths video here but I can't work out how through C# code or Java how to do it, mine works and I would have to go into it again to see all the settings to explain it
     
    Last edited: May 1, 2016
  27. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    316
    I don't get why i can't set a constraint property (align to force) on a prefab from CGF ? it works only if it is an object already in scene. Am i missing something ?
     
  28. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey Gruguir,

    So your doing this through code then?
     
  29. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    316
    No i configure it in the inspector but nothing happens. i'm using pooled prefabs so that may be an issue ?
     
  30. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Can you post a screenshot of you Inspector CGF settings showing your constraint property?
     
  31. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    316
    sure, here it is. I tried at various slerp speed. Also by dropping manually the object in the scene at runtime.
    Again, it works only if a listed object is coming from the hierarchy tab, but wont if its a prefab from the project tab (srry for my approximate english). Now i guess i'm trying to reference a Prefab in a GameObject list so it can't work an i'd better use tag filter.. (yes, tag filter does the trick)
     

    Attached Files:

    • CGF.jpg
      CGF.jpg
      File size:
      86.9 KB
      Views:
      412
  32. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Cool, yeah I would suggest using tags or layers. the problem is when pooling you would have to add every pooled gameoject to the GameObject List in order for it to work that way, which would involve writing a script.
     
  33. arkdzo

    arkdzo

    Joined:
    Oct 22, 2013
    Posts:
    9
    1) want to buy this asset, but cant understand, can I do things like in this race game with this asset, i mean physics sticking to the ground?
    2) What about Playmaker support?

     
    Last edited: May 25, 2016
  34. ChainsawFilms

    ChainsawFilms

    Joined:
    May 28, 2016
    Posts:
    14
    Hello,

    I recently purchased this to have some fun with, and it's amazing :)

    I am currently trying to integrate "3D Adventure Game Kit" so I can get a Mario Galaxy-esque feel with a character running around a planet. I'm very new to Unity and just doing it for fun, and I'm already at my limits with this :)

    In the Adventure kit, you have gravityDirection = Vector3.down, how would I go about over-riding this withe down vector from CGF?

    Sorry for what may well be a very rudimentary question, I have spent a few days on this with no luck so far!

    Thank you.
     
  35. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey arkdzo,

    For that racing game you would have to get your hands dirty and code to get the ship aim towards center of the track, but I would think is possible. I don't have a lic for Playmaker so I don't know whats comparable and whats not, I have heard from some people that it works, but dont know for sure.
     
  36. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185

    Hey ChainsawFilms,

    Sorry for the late reply, I'm not to familiar with 3D Adventure Game Kit, can you send me a link? Is it something like Playmaker?
     
  37. ChainsawFilms

    ChainsawFilms

    Joined:
    May 28, 2016
    Posts:
    14
  38. ChainsawFilms

    ChainsawFilms

    Joined:
    May 28, 2016
    Posts:
    14
    BTW I also picked up SSS as that looks like it will be incredible fun, thanks for these great assets :)
     
  39. Mulbin

    Mulbin

    Joined:
    Feb 8, 2016
    Posts:
    20
    Hi,

    I'm thinking of picking up a copy of Circular Gravity as it looks really awesome! I've had a look at the videos but could you answer a couple of questions?

    I'll be using it on a simulation of planet earth at full scale (using a floating origin to avoid float precision problems).
    What settings would I need for this? Earth has a gravity of 9.8 m/s² which is exactly what I would need it to simulate.

    What are the separate "Force Power" and "Size" fields?

    Also is it possible to simulate weaker gravity at greater distanced from the origin?

    Sorry for all the questions, I could probably figure it all out if I had the asset, but I don't want to buy it until I'm sure it's the right one!

    Many thanks
     
  40. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Awesome glad you like the SSS, I'm hoping to update it with some with some new goodies, as far as the '3D Platformer Game Kit' goes I'm not to familiar with it so I don't really know what to say other then the options for the CGF would be under the CGF->Constraint Properties
     
  41. ChainsawFilms

    ChainsawFilms

    Joined:
    May 28, 2016
    Posts:
    14
    Thank you for the reply, I'll take a look and see if I can work it out :)

    SSS is great fun out of the box!
     
  42. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Sweet glad you like it!
     
  43. SmartyDrawsStuff

    SmartyDrawsStuff

    Joined:
    Dec 15, 2015
    Posts:
    1
    Has anyone ever tried making a small planet orbiting a larger planet ? (with the smaller planet gradually crashing into the larger planet) Any pointers I would very much appreciate it
     
  44. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey SmartyDrawsStuff,

    You could try. You wouldn't be able to do real scale planets but you could try playing with smaller planets like how I have in my Planets demo scene included in the package.
     
  45. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    799
    When you list Gravitational Attraction as a feature I suppose this means a force of attraction that gets stronger the closer you get to its center?
     
  46. ChosenZeus

    ChosenZeus

    Joined:
    May 1, 2014
    Posts:
    16
    Can this be easily used to walk and have objects behave properly on the inside of a hollowed out ball, and also a Torus?

    Thanks!
     
  47. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    Hi

    How would one go about adding path following with this asset? i.e. path-finding on planets.

    Is it possible to have uneven planet shapes? i.e. terrain.

    Many thanks
     
  48. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey c-Row

    Yep, as long as the object is in the CGF area
     
  49. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    185
    Hey ChosenZeus, and numberkruncher

    Currently only works for spheres, you could also turn the sphere inside out and revert the gravity. CGF only provides the gravity for the sphere, so you'll have to do all the grunt work for game functionality like path finding or how you want your char to rotate towards the sphere.
     
  50. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    My question isn't regarding path finding, but rather the path following; given a path how would I direct my actor such that it worked with the planet gravity?