void Update() { // Rigidbody, I use only for the correct stinging and collision. // Speed for player's rigidbodi, we rely only on gravity. // The formula for the speed of acceleration is used: v = at rigidbodyPlayer.velocity = new Vector3(rigidbodyPlayer.velocity.x + currentAccel.x * Time.deltaTime, rigidbodyPlayer.velocity.y + currentAccel.y * Time.deltaTime, rigidbodyPlayer.velocity.z + currentAccel.z * Time.deltaTime); // In order not to take into account the friction of the surface, // the displacement along X will be assumed proceeding from speed and acceleration. // The displacement formula: S = v0*t + a*t*t/2 //transform.position = new Vector3(transform.position.x + calculateSpeed.x * Time.deltaTime + currentAccel.x * Time.deltaTime * Time.deltaTime / 2, // transform.position.y/* + calculateSpeed.y * Time.deltaTime + currentAccel.y * Time.deltaTime * Time.deltaTime / 2*/, // transform.position.z/* + calculateSpeed.z * Time.deltaTime + currentAccel.z * Time.deltaTime * Time.deltaTime / 2*/); // Calculate Speed use formula: v = S / t //calculateSpeed = new Vector3( // (transform.position.x - lastPos.x) / Time.deltaTime, // (transform.position.y - lastPos.y) / Time.deltaTime, // (transform.position.z - lastPos.z) / Time.deltaTime); //rigidbodyPlayer.velocity = calculateSpeed; CalculateAcceleration(); if (transform.position.y < dieY) { EchoLog.Print("[OPS] I fell into a hole."); LevelEventSystem.GameOver(); } }
void OnCollisionEnter(Collision collision) { var collosionLayer = LayerMask.GetMask(LayerMask.LayerToName(collision.collider.gameObject.layer)); if (collosionLayer == groundMask) { underfoot = true; ChangeColor(Color.green); } if (collosionLayer == obstacleMask) { EchoLog.Print("[OPS] Touch obstacle " + collision.gameObject.name); ChangeColor(Color.red); LevelEventSystem.GameOver(); } }