Can you determine the speed of falling?

Could anyone help change my script?

I have an object “Ball”.

My object is a ball and it bounces up.

Every time when I press the left mouse button, “Ball” jumps up.

Each up move adds points.

Now my question.

When the object falls, the points decrease, but the speed of free fall continues to grow.

This causes points to not keep up with the falling ball.

The result is that when the ball stop to the ground, instead of having 0 points it has, for example, 66.

Can you determine the speed of falling?

How do that?

For now, I just add to my object:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Score : MonoBehaviour {

	public Text scoreText;

	[SerializeField]
	int score = 0;

	[SerializeField]
	Vector3 _lastPosition;

	// Use this for initialization
	void Start () {
		_lastPosition = this.transform.position;
	}

	// Update is called once per frame
	void Update () {
		if( this.transform.position.y > _lastPosition.y  )
			score++;
		else{
			score--;
		}


		_lastPosition = this.transform.position;
	
		scoreText.text = "Score" + score;

	}
}

You could check the velocity of the rigidbody as soon as the ball jumps. Have two if statements one to check for positive velocity and if it is add to the score and if it is negative subtract from the score. Have this inside your if statement which check for left mouse button down on line 20.

Can not somehow be addicted to the height Y?

For example, as the height grows and the points grow, as the height fall and the points fall.

Okay I have a solution. I assume that your ball will be jumping on platforms that are maybe generated on the “fly”. So you’ll have to make a list of platforms where you will add all the new platforms you create at the end of the list. You could use the collision detection built in Unity to help you detect what you are doing. Whenever you land on a new and higher platform, you will have to remove the first element in the list (which is the platform below). Doing so, the only platforms in the list will be the platform you are on and the platforms that are above you (Shown in blue).


Whenever you fall and collide with a platform that is not in the list (Shown in red), it will mean that it was a platform below and you will make the player lose points. Whenever you land on the first element of the list, you landed on your own platform and gained nothing. And for the rest (above), you will gain points. One other case is if you fall in the void (not on a platform), you could use a height that is an arbitrary distance lower than the actual platform (red line in the drawing) to see if the ball is lower than that. If it is, lose points and respawn the ball on the last platform. I hope this helps.


The blue platforms shown are the ones still in the ist.
The red ones are not in the list anymore.
The arrows say what actions you did to reach this position. down = fall, up = jump
The red line is the point of falling in the void.
The green circle is your ball.

116631-unit-help.png