Quantcast
Viewing latest article 25
Browse Latest Browse All 416

Mannequin stand up right

so, I'm working a horror game and I have a mannequin appear when your sanity gets low enough it's supposed to stand there and over time it disappears if player does not interact with it, if the player does interact with the mannequin grabs them and snaps their neck. the problem is sometimes spawns on location that are not flat the mannequin model lays on the ground instead of standing upright any suggestions to keep them up right? using UnityEngine; using UnityEngine.AI; public class MannequinAI1 : MonoBehaviour { public Transform player; public LayerMask whatIsGround, whatIsPlayer; public GameObject Mannequin; //Attacking public float timeBetweenAttacks; bool alreadyAttacked; //States public float collisionRange, attackRange; public bool playerInCollisionRange, playerInAttackRange; private void Update() { //Check for sight and attack range playerInCollisionRange = Physics.CheckSphere(transform.position, collisionRange, whatIsPlayer); playerInAttackRange = Physics.CheckSphere(transform.position, attackRange, whatIsPlayer); if (playerInAttackRange && playerInCollisionRange) AttackPlayer(); else if (!playerInCollisionRange) Mannequin.SetActive(false); } private void AttackPlayer() { transform.LookAt(player); if (!alreadyAttacked) { ///Attack code here //Rigidbody rb = Instantiate(projectile, transform.position, Quaternion.identity).GetComponent(); //rb.AddForce(transform.forward * 32f, ForceMode.Impulse); //rb.AddForce(transform.up * 8f, ForceMode.Impulse); FirstPersonController.OnTakeDamage(100); ///End of attack code alreadyAttacked = true; Invoke(nameof(ResetAttack), timeBetweenAttacks); } } private void ResetAttack() { alreadyAttacked = false; } private void OnDrawGizmosSelected() { Gizmos.color = Color.red; Gizmos.DrawWireSphere(transform.position, attackRange); Gizmos.color = Color.yellow; Gizmos.DrawWireSphere(transform.position, collisionRange); } } ![alt text][1] [1]: /storage/temp/201067-error1a.png

Viewing latest article 25
Browse Latest Browse All 416

Trending Articles