Character falls through plattform

hello,

i made a lift and give him following script to move:

var targetA : GameObject;
var targetB : GameObject;

var speed : float = 0.1;

function FixedUpdate () {
	
	//Debug.Log("FixedUpdate");
	
	var weight = Mathf.Cos(Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5;
	transform.position = targetA.transform.position * weight
						+ targetB.transform.position * (1-weight);
						
	//Debug.Log("transform.position= "+transform.position);					
}

tha works fine…
the character has a Box Collider but he always falls through the lift…somebody knows why? I made all like in the 2D Gameplay Tutorial…but on iPhone? Is it possible that the character has to much gravity?

regards

Just to check, does your lift have a Collider attached to it and does your character have a Rigidbody attached?

I’d recommend scanning over the Matrix at the bottom to get a feel for how the various combinations of colliders, rigidbodies, and triggers interact with one another.

Also, you’ll get better performance out of your scripts if you get in the habit of caching component lookups in the Start() functions as opposed to using

function Update()
{
     transform.postion = ...
}

in an Update or FixedUpdate loop. The above code emits as GetComponent call each time through behind the scenes, so by declaring and assigning that to a local variable on start removes that overhead:

var cachedTransform : Transform;

function Start()
{
    cachedTransform = transform;
}

function Update()
{   
    cachedTransform.position = ...etc
}

Lastly, since in this example you’re moving the object through its transform component as opposed to applying physics forces, I’d do that work inside of Update instead of FixedUpdate.

Hope that helps!

Just to check, does your lift have a Collider attached to it and does your character have a Rigidbody attached?

->> Tahnk you…But i have a character Controller, so i dont need a rigidbody apply to him? Isnt it?

I attached a sreenshot of my lift object… i think i all do right but it still does not work?

Maybe you can see what i am still doing wrong.

Ah, the Character Controller, didn’t realize you were using that…it doesn’t act under physics at all. Example, attach a Rigidbody to it, turn on gravity, and you’ll notice that class overrides it - your character will not fall. From the scripting docs on the Character Controller

Anyway, no need re-inventing other answers, head on over to here and you’ll find all manner of solutions:

http://answers.unity3d.com/questions/694/charactercontroller-falls-through-or-slips-off-moving-platforms

thank you…oh no… much more work now :slight_smile: