Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

rail sliding

Discussion in 'Scripting' started by hottabych, May 24, 2015.

  1. hottabych

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    107
    Hello there, I wanna make a 2.5D physics-based racing game, like "Granny Smith".
    Help me implement rail sliding. Player accelerates, jumps to rails, hooks on it and he slides. If rail becomes oblique, then his velocity increases/decreases.
    I think, there should be a complicated Joint + slippery physics material or something like that...
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Is the player on a bike? A skateboard? Snowboard? Is the character physics based? Without knowing more stuff it is hard to say exactly what to try to do. Have you tried anything yet?
     
  3. SnakeTheRipper

    SnakeTheRipper

    Joined:
    Dec 31, 2014
    Posts:
    136
    Here comes the power of rigidbodies !

    Add a rigidbody to your gameobject.

    To accelerate, AddRelativeForce(Vector3.forward * accelerateForce);

    To jump, AddForce(Vector3.up * jumpForce);

    Set your rigidbody to use gravity, so it will accelerate/decelerate on inclination.

    Add WheelColliders to help you roll.
     
    hottabych and krougeau like this.
  4. hottabych

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    107
    Yes, character is a rigidbody based. He is on rollerskates. He catches the railing (or it can be a stretched rope) using a big hook, to cross the chasm.
    Thanks SnakeTheRipper for your response, it will help me. But i still do not understand how to grab the railing/rope and go for it.

    watch at 2:36
    I want to make the same
     
  5. SnakeTheRipper

    SnakeTheRipper

    Joined:
    Dec 31, 2014
    Posts:
    136
    Mmmm I don't know, maybe using colliders you can make it slide on the railing.
     
  6. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    I guess grabbing and losing the railing is a collision detection thing. Once on the rail, I wouldn't bother with physics or slippery materials. I'd just set the Y position of the character to railing.y - lengthOfHook. But I guess to get a more dynamic, animated look you have to find something more sophisticated. You could fire a collision ray with a fixed length (the length of the hook) upwards to the rail. When the ray loses contact, you AddForce a bit and the physics system should do the rest.
     
  7. hottabych

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    107
    Sorry?
    Why will ray "lose contact"? "AddForce a bit" - in which a direction?
     
  8. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    A ray with a fixed length could lose contact. :)

    public static bool Raycast(Vector3 origin, Vector3 direction, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers);

    How about upwards? To get in contact with the rope again? :)
     
  9. hottabych

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    107
    If railing goes down, character will approach to the railing instead of the fixed distance.
    If railing goes up very sharply, character can lose contact