Search Unity

Problem with space ship and player inside it

Discussion in 'Physics' started by Alnos, Jan 12, 2020.

  1. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17
    So here's my problem in this video.

     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,831
    Consider moving environment, not the space ship itself.
    You will eliminate lot of issues.

    Another trick is, to have secondary ghost static ship, which does not move and character with colliders. No rendering.
    Then you just render, with offset position and rotation.
     
    SparrowsNest likes this.
  3. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17

    Kinda like the idea, but for a multiplayer game with 10 playea, moving the environment, will tax the system to much...
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,831
    Why is that? You move players and their ships anyway.
    And in fact, you don't need move complex colliders at all. Like interiors.
    This way, you can make it as complex, as you like.

    You want to look into shift origin topics.
     
  5. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17

    Ok I'll look it up thanks.
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,831
    More accurate term is Floating Origin.
     
  7. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,625
    When you're moving the ship that way (modifying the transform) you're not moving it in a physically way, but you're "teleporting" it from a location to another. At some frame the colliders of the player and the ship will be overlapping and the physics engine will try to separate them. This is done by applying impulses (direct velocity changes), which cause the ship to start moving and rotating no matter its mass.

    A better way of testing that setup is either moving the ship via regular forces or impulses (Rigidbody.AddForce), or making the ship's rigidbody kinematic and moving it via Rigidbody.MovePosition and Rigidbody.MoveRotation from FixedUpdate.

    You may also check out Physics.maxDepenetrationVelocity, which controls the way rigidbodies are moved apart when their colliders overlap.

    This is a good one too, if you still find unavoidable issues with the previous techniques.
     
  8. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17

    Ok so basically instead of moving it via transform to see if it work, I should just pilot the ship tu se if it behave in the same way. Thank.

    I'm using add.force forcemode.acceleration for my player.

    If doing the same for the ship does not work I'll try the other technique. Thanks.
     
    Edy likes this.
  9. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    1,933
    I vote for the moving enviroment solution @Antypodish suggested, I've alwaysed loved it.

    but if you were moving the ship with .transform why not just parent the player to the ship? it's just move with it.

    also - is the 10 players on the same ship? or is it 10 FFA? 5v5? or whatever variation?
     
  10. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17
    Thanks for those question. You just made me realize that I can't move the environment. Its 10 players in a ship, but if the game get popular enough, I whant to make PvP match. 1 ship vs. 1 ship or 10 players vs. 10.

    I'm actually using rigid body. I whant physic in this game.

    OH! And space whale.
     
  11. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    1,933
    We're whalers on the moon, we carry a harpoon
    but there ain't no whales so tell tall tales and sing a whaling tune


    About the other question - when the players wouldn't follow the ships movement, were they parented to the ship in the hierarchy?

    Also, I'll bet you there's a not so insane way of doing the moving environment thing with multiple stationary ships.
    Just have them as normal and project them on all the others enviroment...
     
    Alnos likes this.
  12. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,831
    Right, I stop you here, because you getting into pure speculations, not facts.
    I strongly recommend you, to stress test first and profile, to see, if your concerns are any of issues.
    You seems concern too much, before even trying single solution. And should try at least few, to get the idea.
    Again, stress test. That even before even thinking about any networking, because you won't be doing it anytime soon.

    Once you got some basics working, you could consider do stress test on networking.
    But more than that, you should learn about techniques, to increase performace, which you may be lacking of yet at this stage.
     
    Alnos likes this.
  13. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17

    Oh yes I do lack technique at this point. I'm learning as I go and have so many books and video courses on many subject about programing an unity. I'll get better with time. Thanks for all your helps pals. :)
     
    Antypodish and Edy like this.
  14. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17
    thanks guys this thing is fixed now, but gave me other probleme. i'm now moving my ship with addForce, forceMode.Acceleration.

    doing so my player prefab is thrown backward when the ship move to fast, I tried lots and lots of thing.

    - player prefab as a children or not
    -using rigidbody control or caracter control for player
    -playing with physic Material
    -setting an offsett
    -trying to add the velocity of the ship to the player (wich i'm still strugling to figure out how to properly do it)
    -playng with colision detection
    -playing with gravity

    only thing that kinda work is when I set an insane amount of grativy (-200) it take a greater speed to throw the player back...

    so it's not quite a fix...

    video on the way.

    @SparrowsNest, yup my player prefab is a child. Sorry I miss the question earlier.

    p.s. I did program a OnTriggerExit event for the control to go back to my player. this way i know exactly when i'm thrown back
     
  15. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17
    As you can see the player dont stay in place.....

     
  16. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17
  17. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,831
    Using physics is not perfect, for stacking and moving objects.
    So you may need to learn apply smoke and mirrors techniques.
    Briefly discussed earlier in this thread.

    Also, please use some video recording in the future. For example aTtube Catcher.
    Not recording from hand, using mobile / camera.
     
    SparrowsNest and Alnos like this.
  18. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,625
    Parenting a rigidbody to another doesn't make the child to inherit the motion of the parent. They act as two independent rigidbodies unless attached with a joint.

    I'd work around the solution of adding the same acceleration to both ship and player. Note that if the acceleration is applied to the ship's center of mass, then the acceleration "perceived" at a different position may be different.

    A slightly different approach might be tracking the position changes of the ship at the player's location, then compensate the player for the motion at that location.

    Getting this working correctly would require some research and experimentation, but this is the way I'd work on.
     
    SparrowsNest likes this.
  19. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,831
    @Edy applying same velocity won't work, when rotation is involved with physics.

    Ship has different Com (center of mass) than player. Such approach introduces more problems than solves.
     
  20. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    17
    thanks guys for your toughs. Idea here, and I don't know if it's possible yet. would it be possible to set the interior of the ship in scene2 and the ship and univers in scene1.

    the question is: if the players are in scene2 through script, would it be possible to move the ship in scene1 an get the camera view from scene1?

    just tough of this 5 minutes ago.
     
  21. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,831
    You can have separate scenes if you like.
    But l suggest look into physics layers.
     
    Alnos likes this.
  22. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,625
    I've already stated that in my post. Center of mass should be taken into account and some research is required.

    It's the approach I'd work on because I've already implemented a similar solution that works with vehicles, so they work properly on top of a moving platform. Compensating the velocity of the platform in any point is easy with Rigidbody.GetPointVelocity.
     
unityunity