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 Oobi23 · May 26, 2013 at 01:46 AM · animationraycastcharactercontrollerraycastingcharacter movement

How to make char animation idle

Hi there, I am trying to make my character idle without animating when no movement buttons are pressed. I am just not sure about how to go about this. I am using raycast and this is my coding.

 private var insideObject:Transform;
 
 private var okToMove:boolean;
 private var showingMission:boolean;
 private var showingMission2:boolean;
 function Start(){
     insideObject=transform.Find("Capsule");
     okToMove=true;
     showingMission=false;
     showingMission2=false;
 }
 function Update () {
     if(okToMove){
     //Debug.Log(insideObject.rotation.eulerAngles);
 var dwn = transform.TransformDirection (Vector3.down);
 var fwd = transform.TransformDirection (Vector3.forward);
 var bk = transform.TransformDirection (Vector3.back);
 var r = transform.TransformDirection (Vector3.right);
 var l = transform.TransformDirection (Vector3.left);
 var forwardPos:Vector3=transform.position + fwd; 
 var backwardPos:Vector3=transform.position + bk;
 var rightPos:Vector3=transform.position + r;
 var leftPos:Vector3=transform.position + l;
 
 var hit:RaycastHit;
 
 Debug.DrawRay(forwardPos,dwn,Color.green,5.0); 
 //move front
 if (Input.GetKeyDown(KeyCode.UpArrow)) {
 
 
  if (Physics.Raycast (transform.position, fwd, hit,1)) {
        print ("There is something in front of the object!");
             if(hit.collider.gameObject.tag!="Push"){
     if (hit.collider.gameObject.tag == "endGame"){
                 Application.LoadLevel(0);
             }else{
                 transform.position += Vector3.up;
             }
     
             }
             else{
                    print ("Push!");
                    
                   hit.collider.gameObject.transform.position += Vector3.forward;
                    transform.position += Vector3.forward;
                 
             }
             
     }else{
     Debug.Log("nothing in front");
     
 
             
             
             
             
     if (Physics.Raycast (forwardPos,dwn, 11)) {
     transform.position += Vector3.forward;
                 //did we move to an empty space ?
     if (!Physics.Raycast (transform.position,dwn, .5)) {
     okToMove=false;
     InvokeRepeating("dropDown",1.0,1.0);
     
                     
 }
                 
 }
             
 }
 insideObject.rotation.eulerAngles.y=0;
 }
 
 
 //move back
 if (Input.GetKeyDown(KeyCode.DownArrow)) {
 
  if (Physics.Raycast (transform.position, bk, hit,1)) {
        print ("There is something in front of the object!");
             if(hit.collider.gameObject.tag!="Push"){
     transform.position += Vector3.up;
             }else{
                    print ("Push!");
                   hit.collider.gameObject.transform.position += Vector3.back;
                    transform.position += Vector3.back;
                 
             }
             
     }else{
     Debug.Log("nothing in front");
             
             
     if (Physics.Raycast (backwardPos,dwn, 6)) {
     transform.position += Vector3.back;
                 //did we move to an empty space ?
     if (!Physics.Raycast (transform.position,dwn, .5)) {
     okToMove=false;
     InvokeRepeating("dropDown",1.0,1.0);
                     
 }
                 
 }
             
 }
     
 insideObject.rotation.eulerAngles.y=180;
 }
 //move right
 if (Input.GetKeyDown(KeyCode.RightArrow)) {
 
 if (Physics.Raycast (transform.position, r, hit,1)) {
        print ("There is something in front of the object!");
             if(hit.collider.gameObject.tag!="Push"){
     transform.position += Vector3.up;
             }else{
                    print ("Push!");
                   hit.collider.gameObject.transform.position += Vector3.right;
                    transform.position += Vector3.right;
                 
             }
             
     }else{
     Debug.Log("nothing in front");
             
             
     if (Physics.Raycast (rightPos,dwn, 6)) {
     transform.position += Vector3.right;
                 //did we move to an empty space ?
     if (!Physics.Raycast (transform.position,dwn, .5)) {
     okToMove=false;
     InvokeRepeating("dropDown",1.0,1.0);
     
                     
 }
                 
 }
             
 }
 
 insideObject.rotation.eulerAngles.y=90;
 }
 //move left
 if (Input.GetKeyDown(KeyCode.LeftArrow)) {
 
         
  if (Physics.Raycast (transform.position, l, hit,1)) {
        print ("There is something in front of the object!");
             if(hit.collider.gameObject.tag!="Push"){
             
                 transform.position += Vector3.up;
         
                 
             }else{
                    print ("Push!");
                   hit.collider.gameObject.transform.position += Vector3.left;
                    transform.position += Vector3.left;
                 
             }
             
     }else{
     Debug.Log("nothing in front");
             
             
     if (Physics.Raycast (leftPos,dwn, 6)) {
     transform.position += Vector3.left;
                 //did we move to an empty space ?
     if (!Physics.Raycast (transform.position,dwn, .5)) {
     okToMove=false;
     InvokeRepeating("dropDown",1.0,1.0);
     
                     
 }
                 
 }
             
 }
 insideObject.rotation.eulerAngles.y=-90;
 }
 }
 
 //fall down
 if (Physics.Raycast (transform.position,dwn,hit, .5)) {
     var t:Timer;
     if(hit.collider.gameObject.tag=="HasMission"){
         Debug.Log("has mission");
         if(!showingMission){
             showingMission=true;
             t=GameObject.Find("Timer").GetComponent("Timer") as Timer;
             t.startTimer();
             
         }
     }else if(hit.collider.gameObject.tag=="EndMission"){
     
     }
 
                     
 }
 
 if (Physics.Raycast (transform.position,dwn,hit, .5)) {
     var t1:Timer1;
     if(hit.collider.gameObject.tag=="HasMission1"){
         Debug.Log("has mission");
         if(!showingMission2){
             showingMission2=true;
             t1=GameObject.Find("Timer1").GetComponent("Timer1") as Timer1;
             t1.startTimer();
             
         }
     }else if(hit.collider.gameObject.tag=="EndMission1"){
         
     }
 
                     
 }
 
 
 
 
 
 }
 
 
 
 function dropDown(){
     transform.position += -Vector3.up;
     var dwn = transform.TransformDirection (Vector3.down);
     if (Physics.Raycast (transform.position,dwn, .5)) {
         okToMove=true;
         CancelInvoke();
         
     }
 }
 
 function isShowingMission(){
     
     return showingMission;
     
     
 }
 
 function isShowingMission2(){
     
     return showingMission2;
     
     
 }
 
 
 
 
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

· Add your reply
  • Sort: 

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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Character Animation - even starting if I'm not pressing A or D 2 Answers

Help Understanding Raycast 2 Answers

My Animation Is Stuck On A Frame 0 Answers

Character will not go from Ide to Walk 1 Answer

How to make character controller forward jump a certain distance? 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