I tried making a character jump around the map today.
Conditions:
- Jump a certain height, and don’t be able to jump again until you land
Attempt #1: I set rigidbody.velocity.y = 0 as my condition. It didn’t work because he was able to jump again at the top of his jump.
Attempt #2: I tried using RayCast with a sphere mesh to determine his height, but that was returning distance = 0 constantly. I just could NOT get raycast to work properly. I looked up syntax and everything. Very finnicky function.
Attempt #3: I set my conditions as transform.position.y < 1.5 AND rigidbody.velocity.y < 0.1 and I had to set a timer that started counting down after he jumped once. It would not allow him to jump again before the timer ran out. This all turned out to be a waste though since the player (Sphere) seemed to jump at varying heights. Sometimes it wouldn’t be high at all, and other times it would be a HUGE jump. I used rigidbody.AddForce. I tried synching it to Time.deltaTime, and when that didn’t work I even tried ridigbody.AddExplosiveForce. Same problem: A varying jump height.
Here are my questions:
- Is there an easy way to determine when a character makes contact with a surface? Maybe something about the collider?
- How would you make a player jump once in a dynamic way?
- Is there an easy way to use Raycast? It really didn’t want to work for me.
- How does the game read a script file? I know it reads update every frame, and it reads start once when the script is referenced (or just instantiated?), but -when- does it read the stuff OUTSIDE of update/start? Does it read it multiple times?
- Can someone explain to me how exactly update and FixedUpdate work? Is update updated every frame, with fixedupdate updated every…second? Why are the two important, and when do you use each of them?