PLATAFORMAS DE COLISÃO ONE WAY – TUTORIAL EASY UNITY



Neste tutorial fácil de Unity e C#, mostrarei como criar plataformas de colisão de sentido único usando o efetor de plataforma 2D! No final do vídeo você terá um personagem que pode pular de uma plataforma de baixo e também cair dela! ————————————————– ————————————————– —– LINK para o SERVIDOR DISCORD BLACKTHORNPROD : https://discord.gg/PnJFyzB LINK para o meu TWITTER : https://twitter.com/NoaCalice

source

49 thoughts on “PLATAFORMAS DE COLISÃO ONE WAY – TUTORIAL EASY UNITY

  1. Incredibly useful! May I suggest to set the surface arc to 150, instead of 180. This way, the player can easily jump through the platform without being pushed away by the collider when jumping on the side of the edge!

  2. if someone got a strange bug where you could not go down the platform the second time it
    Here is the fixed code

    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    public class VerticalPlatform : MonoBehaviour

    {

    public float waitTime;

    public PlatformEffector2D effector;

    void Start()

    {

    effector = GetComponent<PlatformEffector2D>();

    }

    private void Update()

    {

    if(Input.GetKeyUp(KeyCode.S))

    {

    waitTime = 0f; //this is where the bug was you had to replace it from 0.5f to 0

    }

    if(Input.GetKeyDown(KeyCode.S))

    {

    if(waitTime <= 0)

    {

    effector.rotationalOffset = 180f;

    waitTime = 0.5f;

    } else

    {

    waitTime -= Time.deltaTime;

    }

    }

    if(Input.GetKeyDown(KeyCode.Space))

    {

    effector.rotationalOffset = 0f;

    }

    }

    }

    ps: the S and space are my games controlls you can replace them with ur games jump and down button

  3. Actually terrible tutorial. What if you have enemies dude? Enemies that… you know, walk on platforms? This is extremely deceiving content, would only work in an exact Celeste clone.

  4. I did it a bit differently, and it seems to solve a few bugs I was having, namely with ground and ceiling detection from my player and the weird pushing up and down that happens to the player when they pass through the platform. This is how I did it:

    [RequireComponent(typeof(BoxCollider2D))]

    public class OneWayPlatform : MonoBehaviour

    {

    new BoxCollider2D collider;

    float top;

    float timeSinceDropThrough = 1f;

    void Awake()

    {

    collider = GetComponent<BoxCollider2D>();

    top = transform.position.y + collider.offset.y + collider.size.y * 0.5f;

    }

    void Update()

    {

    if (GameInput.GetAxis("Vertical") == -1f && GameInput.GetKeyDown("Jump") && Player.Instance.groundCheck.position.y >= top)

    {

    collider.isTrigger = true;

    timeSinceDropThrough = 0f;

    }

    else if (Player.Instance.groundCheck.position.y >= top && timeSinceDropThrough > 0.1f)

    {

    collider.isTrigger = false;

    }

    else

    {

    collider.isTrigger = true;

    }

    timeSinceDropThrough += Time.deltaTime;

    }

    }

    Hope that helps! If you have any questions feel free to ask.

  5. I liked your delivery of the information. I was looking for this topic, but for 3D, so I couldn't use the information. However, the information was still useful. Thanks for making it.

  6. and I thought of a trigerr box collider in the bottom of the platoform that disables, the box collider when the player touches it and when you press the down key u disable the box collider again.

  7. After reading some of the comments I decided to instead just use Physics2D.OverlapCircleAll with the ground check to find the platform(s) that are being stood on, and if it is a one way platform, I used Physics2D.IgnoreCollision with the player's Collider2D to ignore collisions, I set the collisions back to normal once the player's Y velocity is > 0. Decided to post this here just incase anyone else would find this useful. If you have any questions or want the code I used just ask.

  8. Enemies falling through the platform too? My solution was to apply the script and platform effector to the player I want. This was it changes the player's colliders rather than the whole platform. Note, this lets the player go through ALL colliders though.

  9. I’m getting the error:

    AssetsscriptsVerticalPlatform.cs(23,26): error CS1061: ‘PlatformEffector2D’ does not contain a definition for ‘rotationaloffset’ and no accessible extension method ‘rotationaloffset’ accepting a first argument of type ‘PlatformEffector2D’ could be found (are you missing a using directive or an assembly reference?)

  10. i follow the code exactly, but nothing happens when I hold down key,. Is there any difference in GetKey, GetButton and GetAxis? Can I use GetKey("Down") instead of GetKey(KeyCode.DownArrow) ?

  11. Anyone try this using the Brackeys CharacterController2D and have their "isJumping" animator bool set to false by jumping through the platform, interrupting their jumping animation? Any help with solving for that would be so appreciated!

  12. here's an idea:

    Give the platform a tag. Check so that whenever the player is colliding with this tag and presses the Down Arrow Key, he waits for half a second, and then his collider is disabled for a quarter second which will cause him to fall. Then enable it a quarter second later (Note that you should probably try experimenting with how long the wait until your collider is re-enabled, as it might cause some bugs in some cases for example the player's collider is re-enabled while he is inside another collider)

  13. This tutorial doesn't work anymore, I think it got changed in the new update. But maybe try a different tutorial, If it worked for anyone else please let me know.

  14. is there any way to use the platform effector for each, individual tile in a tilemap? I'm trying to setup a way to easily plop down tiles that are platforms. So far I have combined the tilemap collider 2d, composite collider 2d, and the platform effector 2d. I expected each tile in the tilemap to have a platform of its own, but in reality the effector 2d generated a single platform for the tilemap which was positioned at the center of the tilemap.

  15. Heey! Hi Noa xD ! Great Tutorial!! But.. How can i Make this effect to work in just a player? In this case of the video, everything thats are in the colission with platform will faliing down when press ArrowDown :v

  16. Guys there is a little problem with the code, and that is it only resets when you press space and for example what if there was 2 platforms under each other, then the player will keep falling, but i fixed it
    private PlatformEffector2D effector;

    // For flipping the collider rotation

    private float buttonHoldTime;

    //For reseting the platform collider rotation

    public float rotationResetTime = 0.5f;

    private bool rotationIsFlipped = false;

    void Start()

    {

    effector = GetComponent<PlatformEffector2D>();

    }

    void Update()

    {

    if (Input.GetKey(KeyCode.S))

    {

    buttonHoldTime -= Time.deltaTime; //We start the timer (while holding the key) which i made small so it seems instant and not when holding

    if (buttonHoldTime <= 0) // When the time reaches 0 we rotate the collider 180 degres and set it as flipped and we reset the timer

    {

    effector.rotationalOffset = 180f;

    rotationIsFlipped = true;

    buttonHoldTime = 0.01f;

    }

    }

    //Reseting the roation if the player releases the key while the rotation code is running

    if (Input.GetKeyUp(KeyCode.S))

    buttonHoldTime = 0.01f;

    //Reseting Rotation

    if (rotationIsFlipped)

    {

    rotationResetTime -= Time.deltaTime; // We start the timer till the rotation is reset (i used a timer and not made it instant to give the player time to fall down and not get stuck in the collider)

    if (rotationResetTime <= 0) // When the timer reaches 0 we rest the rotation and then the timer and set it as not flipped so we could be able to repeat this code

    {

    effector.rotationalOffset = 0f;

    rotationResetTime = 0.5f;

    rotationIsFlipped = false;

    }

    }

  17. A few solutions for your concerns or problems you're already facing with your game project

    – For anyone concerned with enemies or objects falling: I duplicated the object and changed the Platform Effector>Collider Mask to everything besides the player on the child, and on the parent I did the other way around. Remember to only put your script related to the player on the Game Object related to the collision with the player.

    -In case you believe that the player will be able to press down and jump at the same time, and getting blocked on the bottom of the platform: Based on the script from the video you can change some parts of that and move it from update to a OnCollisionStay2D, and then adding a condition that compares the Y position of the platform to the player. The player might still face a few problems so, unless you go and find a way of getting the Y position of the player from the bottom, a kinda risky workaround would be to add a -1(or more, it depends on how is your project right now) to the player Y position condition so that the comparison would end up like " playerposition.Y -1 > playformposition.Y"

    -Instead of using 180 on the Surface Arc, try something like 100, in case you want the player to be able to get on the platform from a diagonal angle.

    Good luck with your scripts/projects

Deixe uma resposta

O seu endereço de email não será publicado. Campos obrigatórios marcados com *