Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SweatyD · Dec 07, 2011 at 09:58 AM · followfallingzombie

Zombie Follow help

I have a zombie that i am trying to have come at my first person controller. i am using a smooth look at script-> var target : Transform; var damping = 6.0; var smooth = true;

@script AddComponentMenu("Camera-Control/Smooth Look At")

function LateUpdate () { if (target) { if (smooth) { // Look at and dampen the rotation var rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); } else { // Just lookat transform.LookAt(target); } } }

function Start () { // Make the rigid body not change rotation if (rigidbody) rigidbody.freezeRotation = true; } Then adding a sphere collider and giving him a constant force on the Z axis but he seems to keep falling his side then coming at me. Anyone know how to keep him standing? any help at all will be much appreciated

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by john-essy · Dec 07, 2011 at 12:12 PM

eualerAngles.x = 0; look it up in the unity refrence for the correct spelling but this works for me

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SweatyD · Dec 08, 2011 at 08:34 PM 0
Share

what do you mean? sorry im very new to this and know next to nothing about coding.

avatar image
0

Answer by john-essy · Dec 08, 2011 at 11:47 PM

At the end of your script put eulerAngles.x = 0; This should stop the piviting and wierd rotation issues you are having. If you want some simple AI for the ZOmbie to attack your player and always chase you you could do this. NOTE all you need to do is look in the inspector pull your player onto target set the raylength, the turnspeed, speed and your ready just have a play with it. If you do not have any animations for your zombie just delete the animation.CrossFade parts. Also if you want them to constantly come at you you need to find out the size of your level/ terrain. So if it's 500x500 Make your attack range 500 or what ever the highest value. If this has helped you then please click the thumbs up. Need my score up;)

 var target : Transform;
 var zombieController : CharacterController;
 var speed : float = 20.5;
 var backwardsSpeed : float =-20.5;
 var rayLength : float;
 var lookAtPlayerTime : float;
 var turnSpeed : float;
 var hit2 : RaycastHit;
 var distance : float;
 var rangeToAttack : float;
 var beenHit : boolean = false;
 
 function Start()
 {
     zombieController = GetComponent("CharacterController");
 }
 
 function Update()
 {
     transform.eulerAngles.x = 0;    
     distance = Vector3.Distance(transform.position, target.transform.position);
         if(distance <= rangeToAttack)
             {
                 animation["attack"].speed = 0.4;
                 animation.CrossFade("attack");
                 
             }
             else
             {
                 animation.CrossFade("walk");
             
             }
         
     var dir = transform.TransformDirection(Vector3.forward);
     var dir2 = transform.TransformDirection(Vector3.right );
     var hit : RaycastHit;
     Debug.DrawRay(transform.position, dir * rayLength, Color.black);
     Debug.DrawRay(transform.position, dir2 * rayLength, Color.black);
     if(Physics.Raycast(transform.position, dir, hit, rayLength))
        {
                if(hit.collider.gameObject.tag == "Prop")
                {
                    transform.Rotate(0,30 * Time.deltaTime,0);
                    var forward1 : Vector3 = transform.TransformDirection(Vector3.forward);
                 var curSpeed1 : float = speed * Time.deltaTime;
                 zombieController.SimpleMove(forward1 * curSpeed1);
     
                }
                if(hit.collider.gameObject.tag == "Player")
                {
                    var forward2 : Vector3 = transform.TransformDirection(Vector3.forward);
                 var curSpeed2 : float = speed * Time.deltaTime;
                 zombieController.SimpleMove(forward2 * curSpeed2);
                 transform.eulerAngles.x = 0;
     
                }
                
        }
        else 
        {    
                var forward : Vector3 = transform.TransformDirection(Vector3.forward);
             var curSpeed : float = speed * Time.deltaTime;
             zombieController.SimpleMove(forward * curSpeed);
             var rotation = Quaternion.LookRotation(target.position - transform.position);
             transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * turnSpeed);
             transform.eulerAngles.x = 0;
        }      
 }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why Is My Zombie Not Colliding? 4 Answers

How do i make zombies? 2 Answers

how to make zombie follow my charecter 1 Answer

Camera rotation around player while following. 6 Answers

Follow Player Via Waypoints 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges