Attempting to Create Solid Pipe

So, I am new to the forum, so please excuse any errors I may make (not sure this is in the right place, for starters).

I am attempting to make an endless racer. I have used script to procedurally generate my mesh upon runtime, creating 5 pipe segments, stitching them together, and then recycling the pipe I just passed through to spawn a new pipe ahead.
However, my pipe is not solid. I would like to create physics interactions, since my goal is to make a shooter-style game. I understand about creating the mesh collider, adding a physics material, and adding a rigidbody component to the “ship”. However, the ship continues to ‘fall through the world’. I believe the issue to be the Mesh Material, and I can’t seem to figure out how to make one out of my runtime-generated pipe.

Any help appreciated, and thanks.

Based on what you’re trying to do, that should be reasonably simple, so here are some things to check:

  • You said your ship has a rigidbody, but you didn’t say whether it has a collider on it. You’ll need a collider on the ship, or it will “fall through the world”, as you put it. This seems the most likely issue if you’re not seeing any collisions.
  • Make sure none of your colliders have “Is Trigger” enabled.
  • Make sure your pipe isn’t “up-side-down”. Depending on how you created it. This probably isn’t the case, but if your pipe is made of several quads/planes, your collisions will only occur in one direction.
  • If you objects are moving very fast, there can be issues where the object will travel through a collider between frames. If you objects are moving fast, look into the “Collision Detection” options on the rigidbody. The default assumes relatively low velocity collisions. If you have high speed collisions, consider using Continuous Dynamic instead of Discrete.
  • It seems unlikely, but objects can be associated with “layers”, and you can control whether collisions should occur between objects on certain layers. If you haven’t changed any of the layer attributes of your objects, this probably isn’t the issue.

If that doesn’t help, maybe post a screenshot of the Scene view, so we can see what 's going on. You can just copy/paste images in your posts on these forums, so sharing images is pretty easy.

Thanks for your reply;

  1. ‘ship’ is currently just a sphere, with Collider, Sphere Mesh Filter, stock pre-generated object.
  2. Nope. Trigger colliders off.
  3. My pipe IS generated with Quads. How could I tell if it is “inside out”, so to speak? This was actually another thought I had for why the physics wasn’t working.
  4. The ‘ship’ is stationary, the pipes move around it, velocity based on the player’s acceleration. Collision detection was/is set to Continuous Dynamic, as the pipe and ship are currently the only two objects I am dealing with I am not worried about performance.
  5. I have never messed with the Layer settings, so they are at default.

My Pipe…

and my ‘ship’.

Scene view before playing…

and shortly after hitting play, the ‘ship’ has begun his journey into the void.

Any ideas?

PS: Does this forum have spoiler tags or such, for hiding long posts?

I would confirm that your mesh collider on the tubes is working independent of the ship. For example, if you just put a generic box with a rigidbody in your scene, and let it fall onto your tube, does it pass through the tube? Does it collide with the “outside” of the tube? Or the inner surface of the tube?

I’m a little confused about your approach of having the tube move, rather than the ship. Are you locking the Transform of the ship so that it can’t move, under the Rigidbody constraints? What is keeping the ship from moving? How are you moving the objects? If you’re using rigidbodies, then you should generally only move the objects by calling AddForce on the rigidbody. I assume you aren’t trying to manually change the transform.position of either of these objects?

Since I’m a little confused by your approach, I’ll just say what I think you’re trying to do, and how I’d try to make it happen. Ignore this if it’s not what you’re actually trying to do. I’m assuming you’re making a “pipe” that the ship can fly within, such that if the ship hits the walls of the pipe, they’ll bounce off in some way (or crash and explode), but are otherwise forced to stay within the bounds of the pipe. In that case, I would:

  • Create stationary pipe segments that don’t have rigidbodies on them. If the pipe isn’t moving, it doesn’t need a rigidbody, even if it has a collider.
  • Put a rigidbody and a collider on the “ship”.
  • To move the “ship”, call AddForce on the rigidbody based on player inputs. Maybe if “w” is held down, you apply force in the “z” axis, and if “a” or “d” is held down, apply force in the “x” axis, or something like that.

As for as keeping the pipe stationary, and allowing the ship to move, I think that’s pretty important. Imagine you later decide you want more stuff flying around inside your tube, like enemies you need to avoid. You probably want to let them navigate the stationary tube, rather than have to come up with some complex way to cause the enemies all to also be moved/offset/rotated as the tube moves around the player.

Sorry if this hasn’t really helped much.

First, thank you for your replies today. And now, some deeper explanations.

The ship is stationary, at the origin (well, slightly off center.)
The pipes are generated, with the center of the pipe at origin.
The pipes begin to pass around the origin, with the origin staying at the center of the pipe.
The player’s velocity actually affects the speed at which the pipes ‘pass’ the origin.
The player has horizontal movement, which is converted to the rotation of the pipe - the player presses “left”, and the the pipe rotates, making it appear the player moved.
When obstacles/enemies spawn, the will spawn at random locations within a given pipe, as children of the pipe they spawned in.
Obastacles will stay stationary, with the player avoiding the obstacle by “dodging”, which actually moves the pipe, rather than the player. As the obsactles are stationary compared to the pipe, this gives the illusion the player dodged.
Enemies will be able to see the player’s rotation variable, and will apply it to themselves as a rotation translation, allowing them to rotate along the edge of the pipe (as the player does), while otherwise staying stationary to the pipe itself - the enemies never move from the segment of pipe they spawn in, they simply appear to do so as the pipe segments are all moving forward toward the player.

That’s how the project will function, and for simple movement, I actually don’t need the collision detection I am asking about, as nothing ever actually hits the pipe (the player literally cannot, as the pipe always rotates about him, keeping him just slightly above the surface). The reason I want to solve this issue is for weapons fire. I need to find a way to have the weapons fire follow the curve of the pipe, rather than just raycasting forward. My thought was to give each projectile two ‘layers’ - one invisible, that rolls along the surface of the pipe, using collision detection, and the other, smaller and visible, contained within, that actually contains the destruction collision trigger. The first, outer shell, will be on a layer that is culled from physics interaction with anything BUT the pipe.

I am open to alternatives, and ideas. Like I said, my thought was that the Pipe itself has no Mesh Filter (Mesh Filter component), or Mesh (Mesh Collider component), and I cannot seem to find a way to apply these properties, because the actual mesh for the pipe is generated at runtime, and does not exist in the editor unless the game is running.

I could make the player move, but “I don’t wanna” is the best reason I have. By doing it this way, it seems more resource friendly, as once complete the only thing moving will be weapons fire and the pipes themselves. Everything else is just rotating, stationary, with the only physics calls being between weapons fire and the pipe, reducing overhead (or so my thinking goes).

Hope this gives you more insight.

If I’m following correctly, when firing a projectile, you don’t want it just to go in a straight line. Instead, you want it to follow the curve of the pipe, as though it were always a certain distance from the pipe? So if the pipe curves up and down or side to side, the projectile will follow the same path?

That’s an interesting problem to solve. Based on what you’ve said, it sounds like you don’t really want rigidbodies at all, since you’re not really simulating real physics here. I suppose you could do it with rigidbodies, and just keep pushing an object against your pipe trying to get it to hug the surface, but it seems like it would be easier to adjust the position of your projectile manually. I’m not sure the best way to do the math for this, but you can probably find different approaches for it:

“If I’m following correctly, when firing a projectile, you don’t want it just to go in a straight line. Instead, you want it to follow the curve of the pipe, as though it were always a certain distance from the pipe? So if the pipe curves up and down or side to side, the projectile will follow the same path?”

That is an excellent way to phrase it. Unless someone knows the actual math behind doing that, I think I could attempt to have the projectile spherecast outwards, and lock it’s position relative to the pipe it is detecting, constantly moving itself so that it stays within a specified distance of the pipe. Seems feasible to me…

Yeah, this is where I’d have to play around to come up with a viable approach. Another way that I might try is to think of slicing your pipe into an infinite number of circles. When you fire the projectile, your “ship” is located at some rotation from 0 to 360 degrees on that circle. Now, for each “circle” in your pipe, your projectile should be a certain distance above (positive y) from the center of the circle, and rotated by however many degrees your ship started at. But I’m not sure whether figuring out the “center” is necessarily easy, especially given some weird curves in the pipe. And this wouldn’t work at all if you start branching your pipe at some point…

Anyway, sorry I couldn’t offer more practical help. Good luck with skimming your projectiles above the mesh. :slight_smile: (Again, I’d google for that. I expect it’s been done a lot.)