- Home /
How to make these physics
i made a animal in my game and and i gave him a rigidbody to give him gravity. My problem is that i have a terrain and if the animals spawns they have to spawn 500 on the y axis so that they are not able to spawn under the map. But if they fell down to ground they dont fall on the foots they fell on the side. What could i do?![alt text][1]
Answer by AbandonedCrypt · Feb 09, 2021 at 09:24 AM
Rigidbody.freezeRotation = true
in code, or tick the XYZ checkboxes for "Freeze Rotation" under "Constraints" in the Inspector for the rigidbody component on your animal prefab. Also I gave you a solution to your spawning problem in your other question.
i cant see my other question anymore but thanks for your answer!
i found my old question, do you know how i could raycast down. i know how to raycast up and forward but if i write this Ray ray = new Ray(transform.position, transform.down); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, mask)) { Debug.DrawLine(ray.origin, hitInfo.point, Color.red); animalTransform.position = hitInfo.point; }
i get this error:Assets\Scripts\AnimalSpawner.cs(40,61): error CS1061: 'Transform' does not contain a definition for 'down' and no accessible extension method 'down' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)
Blockquote
Blockquote
I advised you to raycast up from your lowest terrain point , as the lowest point is usually more consistent than the highest point. Nonetheless you don't use transform for the direction vector, you use Vector3.up or Vector3.down. Please check your old question for my answer and not the other guys one since he is not taking into account edge cases and teleporting after instantiation is way less elegant than instantiating at the correct position.
Your answer
Follow this Question
Related Questions
Shooting a cannonball. 6 Answers
Why AddForce up is higher than AddForce right? 0 Answers
My object falls through terrain. 8 Answers
Character Controller Pushes Car With Wheel Colliders? 0 Answers
Pinwheel prevents player by moving 0 Answers