Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Oct 20, 2015 at 11:00 AM by devereux for the following reason:

I have solved the problem

avatar image
0
Question by devereux · Oct 20, 2015 at 12:02 PM · scriptingbasicsanimator controllerscriptingproblem

Animator Controller

Alright, So I have a NPC from the Morph3d Male character pack.

In the Object I have a Transform, Animator, Rigid Body, Capsule Collider, M3d Character Manager(Script), and my own script.

I am still trying to just figure unity out, but I have set the Animator controller, to "ThirdPersonAnimatorController".

I made a script, which to my understanding should allow me to move that character towards my character. It however just makes the character rotate spherically in the air.

Can someone help put me on the right track? Here is my script.

 using UnityEngine;
 using System.Collections;
 
 public class WalkToPlayer : MonoBehaviour {
     private Animator controller;
 
     public Transform playerTransform;
 
     public bool isWalking = false;
     public float dampening = 2;
     public int minDistance;
 
     public void start()
     {
         controller = GetComponent<Animator>();
     }
 
     private void update()
     {
         float distance = Vector3.Distance(playerTransform.position, transform.position);
         
         if (distance > minDistance && !isWalking)
         {
             isWalking = true;
 
             setWalking(0.5f);
         }
 
         if (isWalking)
         {
             if (distance < minDistance)
             { 
 
                 isWalking = false;
                 setWalking(0.0f);
             }
         }
 
         // Handles rotation
         Quaternion t = Quaternion.LookRotation(playerTransform.position - transform.position);
         transform.rotation = Quaternion.Slerp(transform.rotation, t, Time.deltaTime * dampening);
        
     }
     public void setCrouching(bool b)
     {
         controller.SetBool("Crouching", b);
     }
     public void setWalking(float f)
     {
         controller.SetFloat("Forward", f);
     }
 
     public void setTurn(float f)
     {
         controller.SetFloat("Turn", f);
     }
 
     public void setJump(float f)
     {
         controller.SetFloat("Jump", f);
     }
 
     public void setJumpLeg(float f)
     {
         controller.SetFloat("JumpLeg", f);
     }
 
 }


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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Issue with animation and gravity. 1 Answer

Issue trying to animate multiple models with same controller and script 0 Answers

Fixing Inverted Camera Controls When Flipped, MouseOrbit 2 Answers

Character Animation Help*! 1 Answer

What's wrong with this simple script? 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