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

Unity2D Spear-Tip Collision similar to 'Getting Over It with Bennett Foddy'

Discussion in '2D' started by numbus, May 7, 2019.

Thread Status:
Not open for further replies.
  1. numbus

    numbus

    Joined:
    Aug 14, 2017
    Posts:
    5
    Hi Everybody,

    I'm working on side-ways 2D platform-like game with the main feature being a spear that the character carries and rotates around them. I'm trying to get precise character control with some elements similar to – but not exactly the same as – the sledgehammer in "Getting Over It with Bennet Foddy."
    (Please note: I'm a bit of beginner when it comes to creating games within Unity, as in I find it difficult to implement mechanics without having a jumping-off board; but I have many years of experience with C# and coding in general and can take off if given direction)​
    _____________________________________________________________________________________________________________________

    So far, I've managed to get a basic 2D controller working with horizontal movement, sprinting, and jumping, as well as a spear that follows the cursor and rotates around the player. Using Rigidbody2D for collision.

    Currently, the controls work like so:


    (https://imgur.com/iQy15je)


    (https://imgur.com/ZEDAXj4)

    There is no movement in these two photos: When the spear tip (the small dark grey box) collides with a surface, the player stops moving and becomes frozen like that in mid-air. Since I'm using a Rigidbody2D, and since the spear and the tip are children of the Player prefab, I believe the spear tip is being controlled by Rigidbody2D collision physics and the player is just stopping as if its feet had collided with the ground.

    Instead, I want the player to still be affected by gravity even if the spear is collided with a surface. So, for example, in the second image, the player would be hanging underneath the platform while still being held by the spear on the top side of the platform.

    This is similar control to Getting Over It. Furthermore, the same behavior should be true for the opposite (colliding with the bottom of surface or top of a surface you are already on)


    (https://imgur.com/my6QQI8)


    (https://imgur.com/fQ1T9r2)

    In the first photo, the player is simultaneously colliding with the top and bottom of two different platforms. If I jump, the player will (currently) get stuck and won't move due to both collisions. Ideally, I would want the spear head to collide with the bottom of the platform and stay in place, but still allowing the player to jump to full height while the spear rotates with the player (assuming the only input is jump straight up).

    In the second photo, the spear is keeping the player above the surface. Ideally, the spear would "drag" across the surface of the ground as the player moves left and right and remains grounded to the floor.
    Once again, all behavior similar to the sledgehammer in Getting Over It so far.

    _____________________________________________________________________________________________________________________

    Beyond this behavior, I want to be able to know if the tip of the spear has collided as opposed to the side to produce different effects:


    (https://imgur.com/7MAJnbc)

    In this example, if the player is balancing on the end of the spear, I want them to slowly tip left or right and fall. However, if the very tip of the spear has collided with the surface, the player should "stick" into the ground and should not tip left or right (visualize a triangular spear tip instead of a Unity cube). Currently, the player stays still in mid-air regardless of the angle of the spear.

    This spear-head "sticking-into-things" can then be used for things such as sticking the spear-tip into a ceiling, where the player can hang down and swing left/right, or sticking into enemies. Ultimately, this is the behavior I want.

    _____________________________________________________________________________________________________________________

    I realize that this is all incredibly hard to describe over text, especially in a WALL of text format. All I'm really looking for is a general hint or direction in the right way, such as "you should look into edge colliders" (although I'm not certain that's the correct answer here), or something similar. I'm not expecting anyone to come up with code that solves this for me.

    All help and any answer is appreciated.

    Here is a link to a full album of the photos used here, if they don't show correctly: https://imgur.com/a/4nQxtGr
     
Thread Status:
Not open for further replies.