FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál

Character controller that can handle sloped terrain and boxy ledge traversal

I am working on a character controller for a 3D platformer in Unity. I cannot find an approach that satisfies me.

I have experimented with these approaches in order to learn about their virtues and pitfalls:

  1. Rigidbody + CapsuleCollider + native physics system (gives you something like Fall Guys)
  2. Rigidbody + CapsuleCollider + custom velocity handling, only using physics system to resolve collisions (this method is illustrated in Catlike Coding tutorial here)
  3. Built-in CharacterController
  4. Custom character controller that uses Unity methods to detect geometric collisions, but does its own collision resolution via depenetration (this method is illustrated in Roystan Ross tutorial here)

See also this video by iHeartGameDev summarizing different approaches.


For my particular use case, each one of these has been better than the last.

After following Roystan's tutorial, I am a big fan of the pushback method of handling collision. Rather than use casts to catch collision before you move your object, you move your object, then find collisions, then resolve them using depenetration.

Roystan's method represents the character as a stack of three spheres for the same reason people favor capsule colliders in 3D: it makes handling slopes much easier (and also because depenetration is easier when you think in terms of spheres).

But the thing I am struggling with is that I don't want the player to be able to slide up or down ledges when traversing them.

Basically, when jumping up or walking off a ledge, I want my character to be treated as a box.

So I am struggling to find a way to accommodate both of the following:

  • I want to support sloped MeshCollider ground (not too noisy, but will definitely be possible to have 4 collision points at a time)
  • I want ledge traversal (up and down) to treat my player as a box

Here are diagrams illustrating what you normally get with a capsule, versus what I want.

Down ledge: enter image description here

Up ledge: enter image description here

My thinking is that I have two options:

  1. Represent the character as a box and use box depenetration techniques to move him along sloped ground (for example, using Unity's ComputePenetration())
  2. Represent the character as a capsule (or stack of three spheres like in Roystan's tutorial) and add special case logic to get the boxy ledge traversal I want

One problem I can foresee with approach 1 is properly doing the depenentration on noisy sloped ground, and one problem I can foresee with approach 2 is properly writing the special cases. (My game is relatively low-poly and retro-styled, so I wouldn't mind the player not appearing perfectly flush with slopes that comes with the box representation of approach 1.)

In any event, I am just looking for advice on how to proceed with this problem. How can I get the boxy handling of ledges while also getting traversal on sloped MeshCollider terrain.

Is either of these approaches better than the other for what I am after, and is there an alternative approach I haven't considered?

  • ✇Recent Questions - Game Development Stack Exchange
  • Get Points Inside StaticmeshEmin
    I am working with UE5 and want to do simulations using Lidar Point Clouds Plugin. i am building a plugin but am pretty new to C++. I want to detect points of a Pointcloudactor that overlap with Staticmeshactors and then color them. I want to build a node that allows those 2 types of inputs, but i cant get to set the input for the Pointcloudactor. Is there any possibility to see the C++ code of the UE5 plugin to use thei method? Hope you understood my english.
     

Get Points Inside Staticmesh

I am working with UE5 and want to do simulations using Lidar Point Clouds Plugin. i am building a plugin but am pretty new to C++. I want to detect points of a Pointcloudactor that overlap with Staticmeshactors and then color them. I want to build a node that allows those 2 types of inputs, but i cant get to set the input for the Pointcloudactor. Is there any possibility to see the C++ code of the UE5 plugin to use thei method?

Hope you understood my english.

  • ✇Recent Questions - Game Development Stack Exchange
  • What's the fastest collision detectionuser289661
    I want to build a simulator using Game Maker in which there are many (up to hundreds) of obj_Cell, each has a radius of 10, (they don't have sprites, they just draw a circle with radius 10). Each step, I want the cells to check around itself for obj_A to see if any obj_A is "touching" it, (has a distance less than 10 from the cell). However, since I have so many obj_Cell and so many obj_A, the most straight forward code (below) will have to be executed tens of thousands of times (number of obj_
     

What's the fastest collision detection

I want to build a simulator using Game Maker in which there are many (up to hundreds) of obj_Cell, each has a radius of 10, (they don't have sprites, they just draw a circle with radius 10).

Each step, I want the cells to check around itself for obj_A to see if any obj_A is "touching" it, (has a distance less than 10 from the cell). However, since I have so many obj_Cell and so many obj_A, the most straight forward code (below) will have to be executed tens of thousands of times (number of obj_A * number of obj_Cell)

//In obj_Cell:
(with obj_A)
{
   if distance_to_object(other)<=10
   {
      //do stuff
   }
}

Is there any possible way to make this faster?

  • ✇Recent Questions - Game Development Stack Exchange
  • Collision Detection in a big map?saloomi2012
    So I've been wondering lately... on games like pokemon (on ds and gba), How did they handle the collision of all those tiles in the map? Should all those collision checks running in the background slow down the game? Do they have it where the collision activates from a certain distance? Do they have a player event where the player is next to a tile that is not able to be walked on? If it is not possible to know the answer, could you give me a solution to that problem? I guess what I am really a
     

Collision Detection in a big map?

So I've been wondering lately... on games like pokemon (on ds and gba), How did they handle the collision of all those tiles in the map? Should all those collision checks running in the background slow down the game? Do they have it where the collision activates from a certain distance? Do they have a player event where the player is next to a tile that is not able to be walked on? If it is not possible to know the answer, could you give me a solution to that problem?

I guess what I am really asking is how to handle collision of almost every tile in a big map.

How detect collision between object1[i] and object2[j] then do something with them in Box2D games?

I am making a simple game with Box2D and SDL2. I have GameObjects vectors for example: 1.vector of Enemy 2.vector of Bullets… in ContactListener class i can detect collision between enemyFixture and bulletFixture. How i can detect contact between Enemy[i] with Bullet[j] and do something only with Enemy[i] or Bullet[j]?! Thank you for your helps.

  • ✇Recent Questions - Game Development Stack Exchange
  • How to resolve collision between wedge and AABB or capsuleArchduke
    I have a 3D world where all of my terrain uses AABBs as collision volumes (think minecraft, but not strictly cubes): I want to add wedge pieces as a terrain option. They'll have various slopes and be able to face all 8 cardinal and ordinal directions. Here's an example of the south-facing wedges: Questions: Is there anything bad about using wedges as collision volumes? Maybe some more standard way that slopes are handled in tile-based 3D worlds? How should I define these volumes in code? How
     

How to resolve collision between wedge and AABB or capsule

I have a 3D world where all of my terrain uses AABBs as collision volumes (think minecraft, but not strictly cubes): game screenshot

I want to add wedge pieces as a terrain option. They'll have various slopes and be able to face all 8 cardinal and ordinal directions. Here's an example of the south-facing wedges: wedges

Questions:

  1. Is there anything bad about using wedges as collision volumes? Maybe some more standard way that slopes are handled in tile-based 3D worlds?
  2. How should I define these volumes in code?
  3. How can I detect and resolve collision between my player entity and these volumes?
  4. How can I stop the entity from being able to walk up steep slopes?

It can be assumed that the player entity will use an AABB for collision. The bottom center point can be used for colliding with the top face of the wedge, but the whole AABB should be used for colliding with the sides. A capsule can be used instead if that's easier.

  • ✇Recent Questions - Game Development Stack Exchange
  • Why is my player not colliding with animated obstacles?Ivan
    I can't figure this out. My obstacles have a basic box collider on them and my player has a rigidbody based controller and collsion detection is set to Continous and when obstacle hits him it just passes trough the player. Belowe is my player rigidbody and collider settings Update: Ok so I found out the following things: Player do seem to react a little when I add a rigidbody to the obstacle, set it to kinematic with continuous collision detection, and I increase player size (this is the most im
     

Why is my player not colliding with animated obstacles?

I can't figure this out. My obstacles have a basic box collider on them and my player has a rigidbody based controller and collsion detection is set to Continous and when obstacle hits him it just passes trough the player. Belowe is my player rigidbody and collider settings

Update:

Ok so I found out the following things: Player do seem to react a little when I add a rigidbody to the obstacle, set it to kinematic with continuous collision detection, and I increase player size (this is the most important change). Still it only moves slightly and obstacle passes trough the player.

enter image description here

  • ✇Recent Questions - Game Development Stack Exchange
  • Instantiated object not tracking collisionJamiePatt
    I have an issue, and I'm not sure why it's happening. I have a prefab that I've built in a colour-changing game. It has the following: Four 2D objects that if they collide with the player (2D collider attached to all), they cause the player to die. One 2D object that if the player strikes, it generates a duplicate of itself with the Instantiate function. All 2D objects are created; The four objects that cause the player to die are being created as normal and continue to cause the player to
     

Instantiated object not tracking collision

I have an issue, and I'm not sure why it's happening. I have a prefab that I've built in a colour-changing game. It has the following:

  • Four 2D objects that if they collide with the player (2D collider attached to all), they cause the player to die.
  • One 2D object that if the player strikes, it generates a duplicate of itself with the Instantiate function.

All 2D objects are created; The four objects that cause the player to die are being created as normal and continue to cause the player to die. However, the object that instantiates the prefab and increments the score can no longer be collided with. The player appears to pass behind it. I'm pasting my code below. I would really appreciate if anyone can offer advice on this:

void Update () {
    if (Input.GetButtonDown("Jump") || Input.GetMouseButtonDown(0))
    {
        thing.velocity = Vector2.up * bounciness;
    }
    scoreText.text = score.ToString();
}
private void OnTriggerEnter2D(Collider2D collision)
{

    if (collision.tag == "plusScore")
    {
        score++;
        Destroy(collision.gameObject);
        Instantiate(barrier, new Vector2(transform.position.x, transform.position.y + 7f), transform.rotation);
        return;
    }

    if(collision.tag != currentColour)
    {
        Debug.Log("You DIED!");
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        score = 0;
    }
}
  • ✇Recent Questions - Game Development Stack Exchange
  • Player-Environment Interaction & Collision Handling in UnityNotLucifer
    Simply put, how would you go about designing environmental interactions? For example, upon pressing the interact button when near a chair, he can sit on it. (Also works with NPCs functioning with NavMeshAgent component.) For now, the interaction system works by raycasting towards players look direction and looking for Interactables and once an interactable is detected, the InputAction for Interact is able to perform its subscribed actions. So, now in my game, I want my player to be able to sit o
     

Player-Environment Interaction & Collision Handling in Unity

Simply put, how would you go about designing environmental interactions? For example, upon pressing the interact button when near a chair, he can sit on it. (Also works with NPCs functioning with NavMeshAgent component.)

For now, the interaction system works by raycasting towards players look direction and looking for Interactables and once an interactable is detected, the InputAction for Interact is able to perform its subscribed actions. So, now in my game, I want my player to be able to sit on a chair or sofa. The sofa interactable component already contains points where the Actor will sit and where it will stand up. (Not consider Stand To Sit & Sit to Stand animations for the time being.)

Flow => Walk Near Chair => Press Interact => Snap to Seating Position (with static sitting pose) => Disable Character Controls Until Canceled => Snap to standing Idle on Cancel.

The furniture already has a collider that blocks the Actors (Player & NPCs) from walking into it and is on a layer that only intractable reside in. The issue is that since both the Actor and the interactable have colliders in it, without disabling one or the other collider, the objects can't be put on each other (even forcefully through code, understandably so because of collisions, duh!)

Am I missing out something or how would you go about this situation to handle interactions that involve overlapping colliders?

❌
❌