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.

Resolved Player going through invincible walls

Discussion in 'Physics' started by Aclypse, Sep 4, 2023.

  1. Aclypse

    Aclypse

    Joined:
    Apr 4, 2022
    Posts:
    6
    aaahhhh i am working on an endless runner and i want to make invinsible walls so the player doesn't fall of the platform. i've created a prefab of the Ground which contains those invinsible walls, but the player still goes through them no matter what. Here's the video (in the video the walls have Mesh renderer on so you can see what's happening, otherwise i have it turned off):


    also, if it's needed, here's the explanation of how the Ground works: I have an empty Game Object called GroundSpawner which spawns the GroundTile Prefab when I hit play, and the GroundTile prefab has the invinsible walls in it (as well as the obstacles).
    Here is the code for the GroundSpawner: https://gdl.space/pohurovape.cpp
    and GrounTile: https://gdl.space/iruqexipah.cpp (if needed)
    and Player's script: https://gdl.space/uhozuhanub.cs

    here is player's inspector:



    and the walls' inspector:
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,537
    You use .MovePosition
    This basically teleports the player to a position, meaning you are forcing it through the wall yourself. Use .AddForce() or .velocity = to use physics, or shoot a raycast forward to detect obstacles
     
  3. Aclypse

    Aclypse

    Joined:
    Apr 4, 2022
    Posts:
    6
    Thank you, finally fixed the issue! But I have another problem now, when the Player touches the wall, she stops. What could be causing this issue? And how can I fix it?
     
    DevDunk likes this.
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,537
    Collision?
     
  5. Aclypse

    Aclypse

    Joined:
    Apr 4, 2022
    Posts:
    6
    Yes, when the player collides with wall
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,801
    You question is vague. Unless you've asked that it bounce, it will stop, clearly.

    Please put some effort into asking questions and spend more time elaborating on the problem.

    Thanks.
     
    DevDunk likes this.
  7. Aclypse

    Aclypse

    Joined:
    Apr 4, 2022
    Posts:
    6
    Sorry, had some problems with publishing the video, but here it finally is

    Basically, the movement and collision with the "invincible wall" functions as it should, BUT when I move the player to the side and stay in contact with the wall for any amount of time, she slows down and often stops moving forward
     
  8. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,537
    Maybe destroy the wall after collision (maybe with a small delay)?
     
  9. Aclypse

    Aclypse

    Joined:
    Apr 4, 2022
    Posts:
    6
    No no no, I don't want to destroy the wall, i want to keep the wall but also make it so that when the player runs against the wall, they don't slow down or stop or anything like that
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,801
    Like any problem, you need to investigate yourself what is causing it to slow-down. You have everything there to do that so check what contacts you get or check what physics materials you're using for friction etc.
     
  11. Aclypse

    Aclypse

    Joined:
    Apr 4, 2022
    Posts:
    6
    In the end I only need to add the physic material to the wall, thanks for reminding))
     
    MelvMay likes this.