Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Issues With a sailing system i'm trying to create

Discussion in 'Scripting' started by LocalizedPricing, Jan 2, 2023.

  1. LocalizedPricing

    LocalizedPricing

    Joined:
    Nov 4, 2022
    Posts:
    4
    Hi there, So i'm trying to create a sailing system. I'm using a version of the Stylized Pirate Ship from comeback, which i've mildly modified(made it so its using primarily primitive colliders as opposed to mesh colliders).

    and i'm using the Modular First Person Controller by JeCase, But i do intend to make my own, just wanted a quick way to be able to move around on the ship.

    The issue i'm having is that for some reason the player doesn't stay on the ship while it's moving. Currently i have a trigger collider on the main deck, And it has a script which parents the player to the gameobject the script is on. when the player exits the trigger area, i set the parent as null. i also tried to put the player's velocity to be the same as the ship's velocity. None of these worked so far, and i'm out of ideas. Any help is appreciated
     
  2. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    Does the player actually get parented? Have you verified this by looking at the hierarchy?
     
  3. LocalizedPricing

    LocalizedPricing

    Joined:
    Nov 4, 2022
    Posts:
    4

    Yes, the player parented to the gameobject i want it to. The player does jump/bounce up above the collider. if i make the collider taller. the character still jumps up
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    If the player has a dynamic rigidbody, parenting it to the ship is not going to do the trick. Dynamic Rigidbodies don't obey the Transform hierarchy.
     
  5. LocalizedPricing

    LocalizedPricing

    Joined:
    Nov 4, 2022
    Posts:
    4
    Any idea how i should go about this? my player and ship use dynamic rigidbodies. and i was hoping i could keep it that way. If not, i'm willing to change the scripts i'm using
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    It's a tricky thing to do in the general sense.

    I would not actually use a Rigidbody for the player in this case. But if you do insist on Rigidbodies, the cure for what Praetor says above is a FixedJoint attaching the two Rigidbodies together, attaching the player to the deck.

    If you're happy with the player always standing perfectly vertical, even on a pitching deck, just use a CharacterController and then have your own boundskeeping that raycasts down to prevent you from leaving the deck collider.

    In that case the deck might be in charge of knowing all the people walking on it and telling them how their former standing point changes each frame... not really sure how that would work in all cases.

    Do you expect the player to lurch from side to side as the deck tilts and have to run uphill if the tilt is extreme? If so that's a bit more of a complication too.

    I've only done a little bit of direct tinkering with this and it was a bit of struggle to get things stable:



    One day I'd love to try something on a ship... it sounds like it could be quite interesting.
     
    chemicalcrux likes this.