I am reading the book learning C# by developing games with unity. In the book you make a hovorcraft that is suppose to hovor above the terrain. it says to check is triggered, on the player object. When i do that the object falls below the terrain. I believe its suppose to.
The book tells me to write a code that will keep it floating above the terrain by using built in method OnTriggerStay. but it still just falls through the terrain.
void OnTriggerStay(Collider other)
{
other.GetComponent().AddForce(Vector3.up * hovorPower);
Debug.Log(“hit”);
}
Am i doing something wrong?
Please format code when posting. Highlight code and press the 101010 button.
This seems weird to me. This methodology will not produce a useful “hovercraft” effect, even if it were properly coded and hooked up. Best case scenario, everything dialed in just right, you’ll have an object that can bob up and down in place. I guess I understand them using this example to teach though. Does the object have a rigidbody component? It needs one to use AddForce. Ensure the force value is great enough to overcome gravity.
Anyway, an object needs a non-trigger collider in order to collide with the environment. Perhaps the book goes on to explain this?
Consider running through some on-site Unity tutorials; I would think they’d cover such basics.