Search Unity

Circular Gravity Force

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

  1. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Hey MarkusGod,

    If you download the Standard Assets there is a scene called CharacterFirstPerson that uses a custom RigidbodyFirstPersonController what should work with CGF. You will have to do some coding so the camera and controls work for the surface under the RigidbodyFirstPersonController.cs But to give you an idea of how it would work on the CGF side, check out the screen shot, pretend the capsules are the RigidbodyFirstPersonController players. Hope this points you in the right direction.

    Cheers!

    Untitled.png
     
    MarkusGod likes this.
  2. MarkusGod

    MarkusGod

    Joined:
    Jan 10, 2017
    Posts:
    168
    Thanks, @LaneMax!
    Indeed your great asset solves most of my problems.
    Is there a way to get this "rigid body to collider point vector", like through events or messages?
    Набросок.png
    And is adding several box colliders is the correct approach for working with shapes like an arch?
    Набросок2.png
    Sorry for bothering you again.
    Mark.
     
  3. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Hey Sorry for the late reply. I don't have an event what would do that, but I could add one in the next update =). I know that the event would be created in the CGF_AlignToForce.cs script and would return the var named transPos if you want to try and add it yourself, but if not I'll keep you posted when the next update. Also for the arch question, yeah currently CGF only supports standard, and convex shapes for aligning to surfaces, so yeah spiting it up into boxs might work. Hope this helps.

    Cheers!
     
    MarkusGod likes this.
  4. MarkusGod

    MarkusGod

    Joined:
    Jan 10, 2017
    Posts:
    168
    It would be nice if you do so. Currently i'm calling your find closet collider and some other functions from your cgf class in on cgf apply event, so that would be if i will have no need to recacl this vector twice.:oops:
     
  5. Choimsung

    Choimsung

    Joined:
    Aug 7, 2017
    Posts:
    2
    I just bought the asset, only to make a character walk on planets.
    I looked at all the answers in this forum, video tutorials, manuals you provided. Yet still...I just couldn't figure it out.
    I'm using the Unity Standard Asset for ThirdPersonCharacter. I saw the other reply you made about this problem, but didn't provide enough information. Also, I used some simple AddForce controls to make a Sphere move, but it also doesn't work as it goes to some point. Could you provide some solution or references that I may look?
     
  6. h00man

    h00man

    Joined:
    Apr 17, 2017
    Posts:
    54
    hey lane,
    sorry if my question have asked before
    do you thinks it is possible to create a force field in shape of complex mesh?
    for example a spiral shape that objects could be lifted up of it. or a cone shape maybe?
    thanks
     
  7. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Hey h00man,

    Yes you can apply CGF on complex mesh's but you are limited to convex shapes or Unity's standard shapes for aligning to surfaces. It might takes some experimenting with multiple shapes to get the effect you want.

    Cheers!
     
  8. h00man

    h00man

    Joined:
    Apr 17, 2017
    Posts:
    54
    hey,
    thanks for answering man.
    i 've got some question
    1 - is there any way to detect objects that are exposed to CGF forces? and change their shader , maybe make them glow.

    2 - i have cgf game object in my sense in shape of sphere
    and when i press space bar it attracts some cubes. is there a way to make difference between those cubes which are closer to the main core of the force field and those who are far from the core?
    3- and do think it is possible to set up a limitation for number of game objects by CGF force?
    i got a CGF force in a shape of capsule and 5 cubes on the ground ,
    and when a press a key i only need 3 of those cubes to be lifted up the other 2 has to remain intact. sorry for long questions
     
    Last edited: Mar 4, 2018
  9. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Hey h00man sorry for the late reply. Yes you can detect objects using some of the CGF supplied events, you will have to get you hands dirty and write a script to do this though. Using this you could also detect how close the objects are to the core based off the distance of the objects from the center of the CGF. The limiting part might be a little hard, but you could try setting the cubes on a separate layer mask, and use 'Non Alloc Physics' under the memory properties to 5, make sure you set the CGF layermask in the memory properties to whatever the cubes layermask is. Hope this helps

    Cheers!

    Capture.PNG
    Event Example

    Non Alloc Physics Example
    Capture2.PNG
     
    Last edited: Mar 31, 2018
  10. shellyalon

    shellyalon

    Joined:
    Mar 26, 2013
    Posts:
    27
    Hi Max,
    I'm interested in CGF but I've got a question first. Is it possible to create a cgf from script on runtime?
    I want to be able to attract/push specific objects with the cgf. Could I create a cgf from script, shape it and adjust its force and then filter only the specific gameobjects i want?
    I haven't found any mention of using scripts in the manual online.

    Thanks!
     
  11. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Yep, there is a whole filter section in the CGF that allows you to filter object. Also you can create the CGFs from code if you like, or create a prefab that contains a CGF and control it that way. Its pretty flexable
     
  12. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Hi,

    I purchased Circular Gravity Force at some time ago. It's great but now I have a little problem.

    There is the Pinart scene where cubes follow the sphere. In my game there is a scene without floor. When player walks around these cubes/platforms raise below like a floor. I also need to add NPC characters (and other players) to walk on this ground as well. They also have the same Force (Sphere/Force/Acceleration,negative Force Power) applied.

    So when the player and the NPC character walk close enought of each other - the cubes below will get double force applied because there are two CGF on the same place. Now, the cubes that make the ground raise too high, above the characters.

    The same problem can be recreated with your Pinart demo. Add second sphere and force like -50. And the forece will become -100.

    Any help how to solve this?
     
  13. notno

    notno

    Joined:
    Feb 19, 2018
    Posts:
    4
    Hi Lane, I'm loving CGF so far. Do you have any plans to incorporate ECS + jobs into a future version?
     
  14. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    I'm hoping so! I'm still trying to assess the amount of work it would take, hoping its not a big refactor. If I have any updates I'll let you know =)
     
  15. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Is there any way you could send me a screen capture or some screenshots?
     
  16. SuperDanOsbourne

    SuperDanOsbourne

    Joined:
    Oct 3, 2017
    Posts:
    46
    Hi, just bought CFG and SSS.
    I'm wondering if there are any more recent successes and examples on making a third person character work with CFG both in aligning to a sphere using gravitational attraction and using nearest collider.
    In my case, I bought Cfg hoping it would be a good solution for a game I'm making where the character hops from one asteroid to another and each one has a gravitational pull and the character can walk in circles around their surface. I'm currently using methods I learned from Sebatien Lague's tutorials which I noticed were posted in this thread. I found CFG later on and thought It could make things much easier and more polished but I'm realizing that it might be more challenging than I thought. One thing is that CFG seems to have changed quite a bit so following a tutorial video can be challenging since the steps and interface are different.
    Are there any recent documentation or videos. Also the links provided in the package via the tools menu in Unity are broken.
    I know I'm going to have a lot of fun with CFG but I just hope I'll be able to use it the way I intended as well.

    Edit: I've managed to make my own third person controller (dated from the controller used in the same Sebastien Lague tutorial) work nicely with the Closest Colliders. Though I only seem so far to make it work when bringing my character into the hovercraft demo scene. In my my own scene, she ends up upside down and changing the alignment doesn't seem to make any difference. a capsule I put in the scene also won't "stand up" it sticks to it's side no matter the orientation though it would switch from one side to another.
     
    Last edited: Jun 19, 2018
  17. SuperDanOsbourne

    SuperDanOsbourne

    Joined:
    Oct 3, 2017
    Posts:
    46
    Ok, So I got my character working nicely with CGF and she's hopping from collider to collider and aligning properly and I will probably post a little tutorial somewhere once I clean up my project a bit. The question I have now is >> How can I dynamically add objects to the Closest Colliders array? I'd really appreciate if anyone could give me a hand figuring it out.
     
  18. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Hey SuperDan,

    Sorry for the delay, here is a quick example how to add a collider to the list

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. using CircularGravityForce;
    6.  
    7. public class AddColliderExample : MonoBehaviour
    8. {
    9.     //CGF object you want to add a collider to
    10.     public CGF cgf;
    11.  
    12.     //Collider to add to CGF object
    13.     public Collider addedCollider;
    14.  
    15.     // Use this for initialization
    16.     void Start()
    17.     {
    18.         cgf._forcePositionProperties.ClosestColliders.Add(addedCollider);
    19.     }
    20. }
    Let me know if this helps.

    Cheers!
     
  19. SuperDanOsbourne

    SuperDanOsbourne

    Joined:
    Oct 3, 2017
    Posts:
    46

    Thanks Lane. This definitely helps.

    My Visual Studio wasn't auto-completing. I just relaunched it and now I can see all my options (DUH!) LOL.
     
    Last edited: Jun 26, 2018
  20. SuperDanOsbourne

    SuperDanOsbourne

    Joined:
    Oct 3, 2017
    Posts:
    46
    This is what I used for a quick test and it works nicely:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. using CircularGravityForce;
    7.  
    8. public class AddMETOClosestColliders : MonoBehaviour {
    9.     GameObject cgfObject;
    10.     CGF cgf;
    11.      
    12.     void Start () {
    13.         cgfObject = GameObject.FindWithTag("CGF");
    14.         cgf = cgfObject.GetComponent<CGF>();
    15.         cgf._forcePositionProperties.ClosestColliders.Add(gameObject.GetComponent<Collider>());
    16.     }
    17. }
     
  21. Matiasbru

    Matiasbru

    Joined:
    Sep 1, 2015
    Posts:
    20
    Hi! I have the same problem, my Third Person Controller gets super slow after reaching a "horizontal" (parallel) position respect to the X-axis. Could you please share your solution?
     
  22. Matiasbru

    Matiasbru

    Joined:
    Sep 1, 2015
    Posts:
    20
    Hi LaneMax, any news about how to control a third person character around a sphere?
     
    graworg likes this.
  23. SuperDanOsbourne

    SuperDanOsbourne

    Joined:
    Oct 3, 2017
    Posts:
    46
    I'll have to take a look at project again to get more specific but basically, I started with a first person character and then added a character model as a child with scripts to pass axis floats to the animation controller. The character controller script is adapted from the one used in one of Sebastian Lague's tutorials on creating planetary gravity. I took out all the code that pertains to gravity and rotating the character's orientation relatively to the planet and let CGF handle that.
    Basically, CGF will handle global rotation and translation while your controller handles local rotation and translation.
    I'll try to get around to posting more details and maybe a video soon.
     
  24. pez

    pez

    Joined:
    Jul 6, 2013
    Posts:
    52
    I could definitely use a video on how to get this working too! My controller is pretty custom so I'm not sure if I'll be able to achieve the same results with what I've currently got. I'm using root motion for animations moving forward, which seems to be working ok with CGF, but my entire rotation setup (which was just referencing axis vector angle based on camera position) is completely broken :(
     
  25. mrowton

    mrowton

    Joined:
    Oct 28, 2015
    Posts:
    5
    I'm having a tough time getting torque force power to work with anything other than input event trigger. I've tried controlling torque - force power through animation, script and state. However, nothing seems to be working. I can see the CFG trying to fire with no effect on the object. When I turn my player controller off and my animator off and just go with the input event trigger with keyboard commands it seems to work. Does the event trigger have input for horizontal and vertical?
     
  26. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    120
    I'm actually doing this same thing. Do you mind elaborating a bit more about the interfacing with the animator controller?
     
    Last edited: Sep 10, 2018
  27. SIV

    SIV

    Joined:
    May 7, 2014
    Posts:
    219
    Hello,

    does this also works with characters ? lets say i want to make a character move on walls or into loops etc.
     
  28. RAgnarFrayer

    RAgnarFrayer

    Joined:
    Jul 9, 2017
    Posts:
    6
    Last edited: Oct 10, 2018
  29. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    This asset is specifically used for providing you with the tools you'll need to manipulate physics for you're game. It's up to you to implement the rules around how the game works, such as player controls and pathfinding. For example, I'm currently making a game Chaotic Void using this tool, and all physics are based off this, but I did have to make the rules around how the game works, such as AI and player controls. You have to think of this package as more of a physics tool and not a drop in game template. Hope this helps

    Cheers!
     
  30. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    I bought this some time ago to use for my game and I got my charactor to work on a sphere with it but having problems with getting in and out of vehicles and getting A.I to run around the planet especially enemy A.I
     
  31. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Correct, you do have to come up with your own solution for pathfinding. I do use Unity's newest navmesh tech in my game, but I don't think they have the ability for full 3D object nav baking such as a sphere, which would be pretty awesome if they ever implemented this.
     
  32. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Yes I find that it can only do quarter a sphere which I think is completely dumb that they didn't implement navmesh to be enabled on all 3D Object Surfaces fully especially as people wish to use this engine for Procedural world games and this linking meshes together well I will have to research it but I 'm not happy about this state of affairs
     
    Last edited: Oct 12, 2018
  33. valentinwinkelmann

    valentinwinkelmann

    Joined:
    Nov 3, 2014
    Posts:
    191
    I'm very interested in this asset but I wonder if moving planets would be possible? i'm thinking of three moons and a planet, the moons have to move. the point is, when i'm on a moon, i have to be able to stand fixed on this moon without the moon moving "under the objects". like the typical "moving platforms". would that be possible in any way?
     
  34. Choimsung

    Choimsung

    Joined:
    Aug 7, 2017
    Posts:
    2
    Hello kind sir.
    I'm using the sphere gravitational attraction. But my character jumps way much higher, and drops slower when its on a higher ground. I guess its because of the newtonian gravity. Is there a way to fix this?
     
  35. SuitsNNukes

    SuitsNNukes

    Joined:
    May 30, 2017
    Posts:
    2
    EDIT: Solved my issue, something with the character controller I was using wasn't jiving with the gravity engine so I just rebuilt one from scratch that does.

    I'm having an issue outlined in this video getting a character to function as illustrated:


    Basically trying to run around the whole planet object, while standing upright like the capsule. Any advice?
     
    Last edited: Nov 2, 2018
  36. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Yeah I think the character controller was setting ether the position or rotation of the player transform which isn't what you want. A genera rule is only apply physics forces to move and rotate your character such as using CGF objects.
     
  37. graworg

    graworg

    Joined:
    Apr 9, 2014
    Posts:
    4
    @LaneMax Help! I need an example what tell me if an object give up a gravitational field, like OnCollisionExit(Collision). I tried to use CGF_OnApplyCGFEvent method but does not detect correctly when the object leaves the sphere of attraction.

    Would it also help me to know how can I access the gravitational field collider?
     
    Last edited: Dec 4, 2018
  38. OZAV

    OZAV

    Joined:
    Aug 9, 2013
    Posts:
    299
    Hey, Max, happy new year, and we are trying to integrate RFPS (realistic fps prefab) player to walk on the (larger) CGF sphere, no luck, so can you please make, and send me some guide on how to do it, or post it here for members download. Much appreciated. For your reference: after the scene starts: the RFPS player is normally the object named FPS Player). Michael. RFPS-AND-CGF.JPG
     
  39. sordidlist

    sordidlist

    Joined:
    Sep 2, 2012
    Posts:
    86
    Hello! I am new to CGF but have had a lot of success with it already! I do have one question I can't quite figure out myself. I am trying to make a player-controlled sphere that can switch between rolling and hovering around. I've been able to essentially copy/paste the roll features from the Marble example with great results, and I think the Hovercraft is almost exactly what I'm looking for for the hover feature. However, I'm trying to get the sphere to hover at a fixed distance above the ground.

    I could put a collider under the sphere but the hovering effect would look really abrupt, and I'm going for something like the hover boards in Back to the Future. I appreciate any tips you might have, and thanks again for making a great asset!
     
  40. sordidlist

    sordidlist

    Joined:
    Sep 2, 2012
    Posts:
    86
    I was scrolling through this thread and saw some users were wanting to make character controllers which use CFG.

    I don't promise that this will apply to your use case, but I am also working on a character controller for a CFG based character and I have made a PlayMaker Action which has helped me.

    Code (CSharp):
    1.  
    2. /*
    3.    CFG PlayMaker Action to allow for state-based changes to gravitational forces
    4.    Author: growling_egg
    5. */
    6. using System;
    7. using CircularGravityForce;
    8.  
    9. namespace HutongGames.PlayMaker.Actions
    10. {
    11.    [ActionCategory("CGF - Circular Gravity Force")]
    12.    [Tooltip("Allows for state-based gravity force effects")]
    13.    public class ChangeCircularGravityForce : FsmStateAction
    14.    {
    15.        public CGF cgf;
    16.  
    17.        [UIHint(UIHint.Variable)]
    18.        [Tooltip("Change CGF force setting")]
    19.        public int forcePowerValue;
    20.  
    21.        public override void Reset()
    22.        {
    23.  
    24.        }
    25.  
    26.        public override void OnEnter()
    27.        {
    28.            cgf.ForcePower = forcePowerValue;
    29.        }
    30.    }
    31. }
    32.  
    I use this file, along with PlayMaker, Rewired, and CFG, and I have successfully made a pretty simple character controller for a spherical robot character who can roll around the map. This action changes the force power of a CFG component when a certain state is reached in your state machine. I have a state machine which detects user input and a second which controls what state my CFG component is in. Hope it helps somebody!
     
  41. imaginethepoet

    imaginethepoet

    Joined:
    Aug 23, 2016
    Posts:
    44
    Good morning,

    I’ve been looking for an asset that I can use in. Number of VR projects. Ideally I’m trying to create a force attraction bound to a VR trigger even for vive, whereby a play can active and pull objects with certain tags into them or repulse them. I believe your system will work but I haven’t see any specific VR responses on here, is this possible? It looked like you might have had this capability in CFG3 from watching your videos

    Thanks
     
  42. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Hey imaginethepoet,

    Yeah I've done this also on my vive, and its pretty easy. You might have to write a little bit of code to bind the controls to the triggers. But its pretty straight forward.
     
  43. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Hey graworg,

    Unfortunately I only have an event that fires off when the force effect is applied to a object. I'm hoping in the future to support this, but sense it uses a Physics.SphereCast its a little hard knowing if it exited the Cast. I'm open to ideas if someone has a simple solution =)
     
  44. Moonlight_Gaming

    Moonlight_Gaming

    Joined:
    Aug 14, 2018
    Posts:
    1
    Hello LaneMax,

    I'm trying to create something similar as you have in the Pivot demo, but with a character following an object. I'm trying to take a shortcut by re-using your Follow script. Since it's a character I need to Move instead of Rotate. However, when making such change in the script it simply doesn't work. I've also tried playing around with the different force types (i.e. change from current Torque setting) but nothing seems to be working.

    If you could guide me in the right direction, it would be much appreciated!

    Thank you!
     
  45. InfiniteDesign8

    InfiniteDesign8

    Joined:
    Aug 22, 2017
    Posts:
    38
    Hi, Im having trouble getting a 2d CFG to effect my Platformer Pro 2 character, do you have any experience getting this to work? I'm using a "physics" character movement in PPRO2...any help would be appreciated. Do you have email support?
     
  46. InfiniteDesign8

    InfiniteDesign8

    Joined:
    Aug 22, 2017
    Posts:
    38
  47. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Hey InfiniteDesign8 crazy sorry about the late response, life getting in the way of things! Do you have a 2D collider on the character, along with a 2d rigidbody?
     
  48. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    128
    Hey @LaneMax , is there a way to enable Acceleration mode for CGF2D ? I can get it only in 3D one.
     
  49. LaneMax

    LaneMax

    Joined:
    Aug 12, 2013
    Posts:
    194
    Hey WildMaN,

    Currently, it's using Unity's ForceModes2D which sadly contains only Force, and Impulse. If they end up updating this in a newer Unity version this will automatically work. Yeah, I wish they were more consistent with the 3D version of ForceModes
     
  50. PunkPuffin

    PunkPuffin

    Joined:
    Jun 17, 2018
    Posts:
    14
    @LaneMax
    Hello, I was wondering if your assets are still supported and if there are any new features coming? Saw them on the Asset store sale and just checking the state of play with the assets.

    Do CGF and SSS work in 2019?

    Many Thanks