Issue with falling through floors on spawning!!!

I have a problem with characters spawning and falling through floors. I have made some scripts to instantiate a prefab player when they join the server, the problem is they have no colliders.

The problem is not with the prefab, as putting the prefab in the map and playing with it, the colliders work.

Any Ideas?

Try instantiate prefab some meters above the floor.
Mayby collider of prefab and collider of the floor are in the same level (Y).

Sry for my english :wink:

I did this, I thought the same thing, maybe the collider is bypassing, but I moved the prefab 3-5 units above the floor mesh, but every time it is instantiated by my spawn command it spawns and falls through the floor.

gwa2100, has your prefab a rigidBody attached?..

If you pause the game and look at the instantiated objects in the hierarchy view, do they have no colliders at all or does it just seem that the colliders aren’t working?

I have been playing around with the 3D platform tutorial “Lerpz Escapes” and ran across the same type of issue when I tried a modification. In the tutorial they want you to try to place the spawn point very precisely so that the enemy robot (NPC) looks correct when it spawns (not floating above the floor, not partially in the floor, etc.) However, I didn’t like that approach.

What I wanted to do was to place the spawn point some distance above a platform, for example, and then let the NPC determine when it should stop. I was able to accomplish this by putting a box collider below my spawn point and set the “Is Trigger” box so that it would “talk” to my NPC. The NPC has a Character Controller attached to it by the way.

Then I added a script, which was initially borrowed from another part of the tutorial, to my NPC behavior to do two things. First, I set a “spawn” flag at startup that I could use during the update cycle. Second, I added code that moved the NPC from the spawn point down toward the platform on every update cycle. When the NPC encounters the box collider, the Character Controller received a message. I use that event to clear the “spawn” flag which has the effect of stopping the downward updates. The overall effect is that the NPC stops on the platform where I want it.

Here is the enemy spawn behavior script. I have some debugging messages in here so that I could see what was going on. Maybe it will be helpful for you.

// variables to use
private var debugText : String;			// string to hold debug text.
private var enemyNum = 0;
private var spawnFlag = 0;			// flag to indicate that we have just spawned.

var gravity = 10.00;
var collisionMask : LayerMask;

private var velocity = Vector3.zero;
private var position : Vector3;

function Start ()
{
	
	// indicate that we are spawning
	spawnFlag = 1;
	
	// initialize the position vector
	position = this.transform.position;

}
function Update () 
{
	var controller : CharacterController = GetComponent(CharacterController);
	
	if (spawnFlag == 1)
	{
		print ("...Inside the EnemySpawnBehavior script...");
	
		debugText = "EnemySpawnBehavior: " + this.name;
		print (debugText);
		debugText = "Enemy Location:  x = " + this.transform.position.x + "\t" +
												  "y = " + this.transform.position.y + "\t" +
												  "z = " + this.transform.position.z + ".\n" +
						  "Spawn Flag: " + spawnFlag + ".";
		print( debugText);
			
		velocity.y -= gravity * Time.deltaTime;
		moveThisFrame = velocity * Time.deltaTime;
		distanceThisFrame = moveThisFrame.magnitude;
	
		if (Physics.Raycast(position, moveThisFrame, distanceThisFrame, collisionMask))
		{
			enabled = false;	
		}
		else
		{
			position += moveThisFrame;
			transform.position = Vector3(position.x, position.y + 0.75, position.z);	
		}

		if ( controller.isGrounded)
		{
			print("We are grounded!!!!");
		}
	}
}

function OnTriggerEnter ( other : Collider)
{
	print ( "EnemySpawnBehavior script Caught OnTriggerEnter - Stopping the enemy position updates.");
	spawnFlag *= -1;
	debugText = "Spawn Point flag set to " + spawnFlag + ".";
	print (debugText);
}

It may not be perfect but it worked for me and helped me understand better how to handle this situation.

You don’t need a RigidBody. While it may be a work around that solves this particular problem, that is the job with the Character Controller. RigidBody is meant for physics interactions that are more realistic than a turn-on-a-dime character.

I also struggled with weird problems with the Copper enemies falling through the level using Unity 4.0 – the tutorial is a little out of date.

What I found that worked was modifying the Character Controller values
Center: Y:0.42
Height: 1.17

This keeps it moving on the ground, and prevents collisions with the “helmet” object that has a rigid body attached to it that would otherwise cause stuttering movement on the ground due to rapid collisions. You can enable “IsTrigger” but it’s not really the best way to solve the problem.

scripts?physicals don’t work idk why