Intractable moving objects

What I’m trying to do is have a platform that is threatening to crush a player walking through a narrow hallway and when he hits a trigger the platform will close in on him… I made a simple version without the trigger to test my theory

var speed = 2.0;
var TimingOffset = 0.0;

private var OriginalTransform : Vector3;

function Start(){
   OriginalTransform = transform.position;
}

function Update(){
    var Offset = (1 + Mathf.Sin(Time.time * speed + TimingOffset)) * 2 / 2;
	transform.position = OriginalTransform + Vector3(Offset, 0, 0);
}

It moves the platform however the character goes right through it, I also wish to know how I can integrate it with a trigger.
Thanks.

Hello!

Triggers can be trespassed, what you are looking for is for a collision detection :smile:

so instead of using OnTriggerEnter use OnCollisionEnter

hope it helps :slight_smile:

I know the basic functions to use for the collision between the player an the moving wall, I just don’t know how to phrase it in code… but I’m mainly focused on why my moving wall doesn’t push the player, unless your saying something like killing the player on collision with the wall, its not exactly what I was looking for but thanks for the pointer :smile:

When you just move colliders kinematically like this, you don’t get the physical behaviour that you do when you add forces, etc. To enable the wall as a trigger, you just set IsTrigger to true in the inspector and add an OnTriggerEnter and/or OnTriggerStay function in your moving wall script. It is fairly straightforward to move the player object directly from this script whenever the player is inside the trigger collider.

Well, I would’ve never looked at it that way, seems a little jury rigged to be honest :stuck_out_tongue: but it’ll definitely work… however could you give me a simple example I don’t fully understand the Reference and how I can affiliate the wall with a separate trigger…
Thanks for the pointer