So i have this script, and I know there are multiple questions but i couldn’t find an exact answer for what I’m doing
var stretch = false;
var defaultPosition : Transform;
var stretchPosition : Transform;
var speed : float = .01;
function Start() {
stretch = false;
}
function OnCollisionEnter ( obj : Collision ) {
if (obj.gameObject.tag == "Player"){
Debug.Log ("player hit");
stretch = true;
}
}
function OnCollisionExit ( obj : Collision ) {
stretch = false;
}
function Update () {
if (stretch){
if ( transform.position.y < stretchPosition.transform.position.y){
transform.position.y += speed;
}
else {
if ( transform.position.y > defaultPosition.transform.position.y){
transform.position.y += speed;
}
}
}
}
what i am trying to do is when the player jumps on the platform it moves up till it reaches a certain point. Then when the player jumps off if returns back to the original position. two things, 1 i can’t get my collider to recognize that the player is in contact. it doesn’t seem to do that. Idk if it is because it is a child of a child of an object. otherwise i may switch this to use a trigger box don’t know yet. The second thing is i use the y position of a waypoin set to move up to. but with the if function it doesn’t stop it just keeps going up. Any help would be great thanks.
Make sure the object with the collider on it is tagged Player.
Use debugger or add some Debug.Log() statements to make sure OnCollision events are being fired.
If you are going to move your object with transforms not physics it might be worthwhile making the player a child of the platform whilst they are on the platform.
For your last question … transform.position.y += speed; should be transform.position.y -= speed;
Thanks for your answers but I’m doing everything u said, the main thing is though it for reason isn’t receiving any collision cuz I do have the debug log as you can see my code. But another thing is that I get the platform to move but when it goes to start moving it goes past the waypoint height. So the if is stopping it. But was wondering does it matter if it moving as a child object that it should move locally?
so i have the debug out, nothing comes up when come into contact. But the platform’s parent object is on an ignore collision layer i have set up, and the the check boxes are all unchecked for that layer. BUT the layer of the actual platform is set to default for a layer. I don’t think it a layer cuz it wouldn’t even stay up on the platform if it is just the layer. BUT i also have a script set up that it turns the platform off and on if a line up event is activated. But it doesn’t recognize any colliding. anymore help for me?