Announcement

Collapse
No announcement yet.

Physics: where i should look to add force for actors each simulation loop?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Physics: where i should look to add force for actors each simulation loop?

    I know i can do it even in blueprints with for each loop. But i think its bad to mix some loop with physics simulation.

    My goal is simulating gravity and thus gravity movement for bunch of objects. Nothing like KSP, i just want speed vector & mass of object (which is done and in engine).
    Now i need some proper way (or best) to add gravity pull force (Towards 0,0,0) each physics simulation tick.

    My problem is that i do not even know where to start looking for this in code.

    ps.
    Making new type of physics constraint that pulls object back when stretched with force equal to gravity pull would also work. But this is less elegant solution imo.
    Last edited by Nawrot; 01-15-2015, 07:06 AM.

    #2
    I achieved planetary orbit by iterating through a collection of actors and applying the force per tick and it worked very well. What makes you think it is bad to mix loops with physics simulation? But in any case, you could apply the force directly in the actor's class to avoid looping through.
    Last edited by ULLS; 01-15-2015, 07:53 AM.
    [FREE] Procedural Bridge Blueprint, [FREE] Spline Enabled Ivy BP

    Comment


      #3
      Because i am not sure if my tick event happens as many times (or in constant proportional amount) as physics tick.
      This may cause weird behavior when fps is low or very high, etc. It is just unsafe or asking for trouble later.

      But this does not matter i found some old topics about subject, it is not trivial to add that stuff in proper way.
      Also it is quite high in epics trello ranking for physics, so we may get it soon.

      I solved this in a bit different way, and it suits my game better, I added constant length constraints to all orbiting bodies.
      I kind of do not want real kepler behavior for those actors because then gameplay would be too complicated.
      Perfectly spherical orbiting instead of elliptic is kind of what i actually need.

      Comment


        #4
        Ah okay, I procedurally generated my solar system within the constructor of a single class, looping through was the easiest solution. It worked really nicely though and I had a really great FPS count, it also adhered to kepler's laws. Still though, if I were to do it again, I would probably have a base 'satellite' class and add this object to my solar system class, then apply the force from there and enable the physics sub stepping feature (as I've not tried this yet).

        I initially had planned on having everything 'on rails' and tried it out but doing it with the physics engine resulted in a much nicer effect.

        Anyway, I wish you the best of luck with your project
        Last edited by ULLS; 01-15-2015, 11:22 AM.
        [FREE] Procedural Bridge Blueprint, [FREE] Spline Enabled Ivy BP

        Comment


          #5
          Just out of curiosity, would you not suffer the same problem by handling it the way you've decided to go? What I mean is if you use physics constraints to lock the planets in a circular orbit you'll still need to apply a force to the constrained actor in order for it to move or are you simply rotating the planets around the sun outside of the physics engine altogether?
          [FREE] Procedural Bridge Blueprint, [FREE] Spline Enabled Ivy BP

          Comment


            #6
            Physics constraint makes orbit circular, you apply impulse, remove damping and it will rotate forever, but then there is problem of moons (they drag their planet).

            Pure physics simulation introduces slight drift, orbits are stable for few first rounds, then they just fall apart. So you kind of need to snap all planets/moons to correct location every circle/ellipse they do.

            Instead all of this i just calculated speeds and orbits (well really I googled parameters and scaled them to size of my game). Now i calculate positions then update actors location trough interpto for orbit distance and rotation.

            What i wanted physics for was random meteorites around planets, physics (plus constraints) is great for this, but pure physics would allow me to shoot them away from orbits etc. So i thought it is not that hard to implement for bunch of actors, but then i found about those older topics, trello and that it is not as trivial as i thought.

            PS. And real planet motion is boring for game, so i am slowly drifting from simulation to what is fun motion there.
            Last edited by Nawrot; 01-16-2015, 12:48 PM.

            Comment

            Working...
            X