Mark on the ground for falling object in Unity3D

Hello, I wanted to make an object fall from the sky to the ground. I already have the object spawning and falling, but I wanted to have a mark on the ground so the player knows where the object is falling. Is there a way to do that?

[EDIT] Check the comments for more info!

There is a dirty way to do it, and a more general, cleaner way.

Dirty way

I did this when I was first learning Unity and the free version did not yet have shadows. Create a prefab with the marker you want to show on the ground, and Instantiate() it at the same xz position as your falling object, but very slightly above your ground (i.e. GameObject markerInstance = Instantiate(markerPrefab, new Vector3(fallingObjectPosition.x, 0.05f, fallingObjectPosition.z), Quaternion.Identity); ). The only issue with this is that if the falling object gets Destroyed(), the marker will remain. So you can assign the markerInstance to some variable of a script on the falling object, and in the OnDestroy() of that script do if (marker != null) { Destroy(marker); }

Cleaner way

Your falling object will need a script that controls the creation of your marker, e.g. FallMarkerControl. FallMarkerControl needs a GameObject fallMarkerPerfab field, to which you need to assign the prefab for a generic fall marker object (I would write [SerializeField] private GameObject fallMarkerPrefab = null;, but this is a personal preference). Then in Start() you cast a ray from your falling object downwards (or more general, in your “fall” direction), and the position that you hit is where you need to position a new instance of the fallMarkerPrefab.

Something like this:

[SerializeField] private GameObject fallMarkerPrefab = null;

[SerializeField] private  Vector3 fallDirection = Vector3.down;

private GameObject fallMarkerInstance = null;

private void Start () {
	if (fallMarkerPrefab != null) {
		RaycastHit hit;
		if (Physics.Raycast(new Ray(transform.position, fallDirection), out hit)) {
			Vector3 fallPosition = hit.point;
			fallMarkerInstance = Instantiate(fallMarkerPrefab, fallPosition - 0.05f * fallDirection, Quaternion.identity); // small displacement to avoid z-fighting with the ground
		}
	}

	private void OnDestroy () {
		if (fallMarkerInstance != null) { Destroy(fallMarkerInstance); }
	}
}

Note that this second way also only works correctly if you have a more or less flat ground, otherwise your marker will float (of course, that can be solved if you rotate your fallMarkerInstance with the normal of the raycast hit).

Hope this helps!

@PlatPlayz Is the surface to be marked flat?