Hello,
Im doing a 3d platformer with gravitation changing in certain places.
There are platforms that should fall after certain amount of time after player touches it.
If the platform is oriented in the part of level where i changed gravitation for player, i want it to start falling in current players down direction.
Im using
transform.Translate(fallingDirection * fallingSpeed * Time.deltaTime);
to make platform fall.
I tried using -transform.up as the local downwards for collapsing platforms.
While debug.ray made while using it looks fine, platform rotated 90 degrees on x axis starts goin up.
I managed to do it using
public Vector3 fallingDirection
and manually finding in Inspector which direction will get me the desired fall.
But i got so confused and i dont like this solution cause its not elegant and potentially problem making.
Can anybody help me, and explain what am i doing wrong maybe ?
full code of collapse platform script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CollapsingPlatform : MonoBehaviour{
//////////////VARIABLES//////////////////////////////////
private bool startFalling = false;
public Vector3 fallingDirection;
public float fallingSpeed;
public float waitTime;
private float startFallingTime;
private bool contacted = false;
///////////////START///////////////////////////////////
void Start(){
}
//////////////ONTRIGGERENTER///////////////////////////////////
void OnTriggerEnter(Collider other){
if(other.tag == "Player")
{
startFalling = true;
if (contacted == false)
{
startFallingTime = Time.time + waitTime;
contacted = true;
}
}
}
////////////////UPDATE//////////////////////////////////
void Update (){
Debug.DrawRay(transform.position, transform.up, Color.green);
if(startFalling == true && Time.time > startFallingTime)
{
transform.Translate(fallingDirection * fallingSpeed * Time.deltaTime);
}
}
}
Platform game object has:
box collider to interact with player, so that he can stay on it,
trigger collider to trigger falling,
mesh of course,
and rigidbody added because i couldnt get my boundary->destroy script working in different way.
Thank you for any help in advance,
Greetings