Unity terrain collider intermittently missing collisions - c#

I am experimenting with the terrain tools. The app has a cube (0.2x0.2x0.05) that flies around representing a quadcopter. It has a collider (not set as trigger) and rigidbody. It is controlled by addforce() etc - ie its position and rotation are not changed directly.
It works quite reliably in scenery constructed from primitives (cubes, spheres etc).
I am now trying out the Unity terrain tools package (I'm using editor 2019.3) and have a simple test terrain (500x500m) with rock, scree and sand layers.
What I find is that sometimes when flying it directly into the terrain just to check what happens, it goes straight through. Often it collides OK, but not always, maybe 50:50.
The FixedUpdate() rate is the standard 20mS.
I'm not sure if there is any step I have missed? I am just using all default settings on the terrain. It has the standard mesh collider. It isn't set up just as a trigger or anything (anyway, mostly it works OK).
Is this something I've done / not done, or is this a known issue - is there a workaround?
STOP PRESS: Testing still in progress, but have a feeling this may be to do with the collision type selected in the rigidbody - see answer below.

Testing still in progress, but it strongly appears this is be to do with the collision type selected in the rigidbody. Default is discrete, but there is information in the Unity docs that with fast moving bodies, it may be necessary to use continuous (at some CPU cost) to avoid missing some collisions.
The problem has not happened since the type was changed to continuous.
The quadcopter is after all, quite a fast moving body, up to 150 kph, and small.

Related

Unity Procedural Game Optimization

I am currently developing a 3d dungeon crawler which implements a procedural dungeon generation system which works perfectly fine. However the game is not very performant. I have tried a few optimization tricks I heard like:
Adding LOD Groups to each room prefab (this works perfectly fine), has impact on fps and batches
Tried addig static batching, I made every room prefab static and enabled dynamic and static batching in the player settings, however there is no change in the batches count or the saved batches count.
Tried addind occlusion culling but i cannot bake it before the game, as it's a procedural generated world.
The room prefabs are low poly rooms and are not even decorated yet, just the floor and walls and torches.
I should mention that i am using deffered lightning and I am activating the torch point lights as the players walks in the room. There aren't any baked lights everything is realtime. Every room prefab uses the same metrial and is not copied when the room is instantiated.
Some screenshots to help you understand better:
If you need anymore info, please don't hesitate to ask. Thanks you
Might be overkill, but have you thought about making the meshes a subscene / an entity using dots. Then just handle the colliders separately.
Hope that works for you.
If that is still having issues you may consider removing any colliders that are outside of a certain distance from you, and loading them in when you get close.

Unity 3d, What Universe.physicsTimeStep is?

i was trying to duplicate this solar system simulation project and i have a question:
What is "Universe.physicsTimeStep"? i searched in unity manual and scripting API but i didn't found anything. Can someone explain me? Thanks
Historically, when games simulated physics, they did so by updating the physics simulation once every frame. For example, to find distance travelled they would use velocity * timeStep, where timeStep is the time between frames.
Nowadays, especially with multithreaded game engines, the physics simulation runs (somewhat) independently of other simulations and rendering. For example, the rendering could be done at 60 frames per second but the physics is only updated every other frame (i.e. 30 FPS). The more frequently the physics simulation is updated (i.e. the lower the time step), the more accurate the physics simulation is.
Sometimes, the time steps of various systems are adjusted so that the game rus 'properly' even when the hardware is a limiting factor. Typically this is done by 'dropping' (i.e. skipping) render frames, but update frames could be dropped as well. Some games, especially platformers and other games where physics is very important, will always run the physics simulation with the same time step so that running it on a slower CPU (which would result in a higher time step) doesn't affect gameplay, such as by making difficult jumps easier.
In your case Universe.physicsTimeStep seems to be the time step used for updates in the game. It also appears to be a fixed time step, so it will always be the same. If the game is running slowly, it will drop render frames but keep updating the physics.
That is a public constant in the class Universe(You should see Sebastian Lague's Solar System Github repository.
It's clearly mentioned there

Are My Unity 2D Transform.Position Units Changing Between Builds?

I've put together a little Git repo to share with you some scripts from the Unity 2D platformer I've been working on. I have written some basic WASD movement control in the Movement.cs script (under Scripts/Character in the repo) and it is working really well. It does everything I need it to do, and while it is basic, I intend to polish it up a bit over the course of the development of the game. However, I've been noticing that every time I build the game, every moving entity moves at a faster speed. The "AI" (yes I use the term very loosely) that I programmed into enemies like the Chompas and BadBirds seems to be far too fast or far too slow, as are user-controlled movements and animated powerup bubbles.
Now, I believe I've traced it back to the way I create translations; I add vectors to Transform.Position whenever I need to move an object or entity. These vectors accept float values as their parameters, and seeing as I'm not entirely clear on what those values represent, I feel that may be where the issue lies. Are these distance values representative of some dynamic system of measurement that might be changing between builds? If so, how might I standardize my distances? Am I totally off the mark? Lol. Any and all help is greatly appreciated.
To be perfectly clear, this issue occurs every time I hit play, regardless of whether or not changes have been made. Thanks again!
Git repo
Try multiplying your movement by Time.deltaTime.
If you don't do this (which it doesn't look like you are), then all your GameObjects will move at inconsistent speeds. The reason for this is that void Update() get's called once every frame, and the amount of frames that get drawn every second is variable (sometimes your game will run a little faster than at other times), and so your speed will be variable if you don't multiply it by Time.deltaTime (Time.deltaTime is the amount of time that has passed since the last frame, see the documentation)
Another option is to use Unity's built in physics system with FixedUpdate(), which get's called at a fixed rate.
I would strongly recommend to follow online tutorials for how to make a platformer controller etc., such as this one. Doing this will help teach you good practices and how to avoid common errors.

Floating rigidbodies script in Unity

I'm trying to create simple game where you jump around with ropes hooking to flying islands. I want islands to just float and when hooks himself to this island he begins to pull it to himself, but he is also able to swing on it. After he releases the rope islands slows down and stops (but I guess this is done by the rigidbody drag). Can you tell me how this script could work because I don't have any good idea of doing this.
You should disable gravity for the islands' rigidbody, first of all. That way, they will float, but things like inertia will still apply.
If you want your character to pull the islands to himself when grabbing them with a rope, you could use Rigidbody.AddForce(Vector3 vec3) and pass the vector opposite to the direction the rope is aimed at as a parameter (you should use Vector3.Reflect() to do that.)
This will get you started, but there are more ways to improve the effect, such as making the islands gradually slow down after pulling them. I'd suggest multiplying the island's velocity by a fraction of 1, in that case, but there are other ways to do it.

Detecting an object colliding with itself - snake or rope example

I have a custom mesh I've created for a game object. I want to do some actions when it touches itself. I tried attaching the collider and the script to the mesh. However the script is called only when colliding with other objects. How can I detect colliding with itself?
In a game physics engine, such as PhysX: there is no meaningful sense in which a collider can collide with itself.
Note that, in games and 3D engineering, "things" almost always have more than one collider.
For example, a doggie might be made of, oh, seven or so colliders (you can imagine one for the torso (perhaps a sphere there), four legs (probably capsule or just rectangle), one for the head (spehere again), and if relevant in the game one for the tail (probably just a rectangle - or maybe two small spheres). For a car, you might have say three boxes for the overall shape of the body, and you likely have individual colliders for "where you need to know what hit" ... eg, the bumpers, maybe the doors if you expect it to be bashed there, and so on.
Now,
regarding your question, it looks like you have -- for example -- a humanoid, which would have a number of colliders as described in the previous paragraph.
It could be that, for example, the arm collider can hit the leg collider, and you want to know that.
It is impossible to help you with your question, unless, you explain what your scene is in general terms...
--
If you're making a snake or perhaps rope, do what Gunnar said. The simplest solution is a number of sphere colliders.
Quite simply say your snake is 10 centimeters thick. Say your snake is 2 meters long. Quite simply have sphere colliders about 9-10 cm in size. Separate them so they are not touching one another but a bit spaced. So for 2m you might have about 15 of them. That's all there is to it.
Please note that engineering ropes / snakes is far from easy.
I encourage you to glance at the AssetStore and look at the may excellent rope/snake packages available.
Realise that it can take man-years of engineering to develop a perfect rope system.
Understand that an everyday aspect of Unity (or game engineering in general), is that you have to use an existing, often well-known solution, for the problem at hand. Good luck.

Categories