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 /
This question was closed Oct 13, 2012 at 08:27 AM by whydoidoit for the following reason:

OP couldn't edit the question to get the right code in. Has now posted a new question.

avatar image
0
Question by Konkor4 · Oct 12, 2012 at 11:39 PM · rotateturnbend

Rotate model, turn around only, no bend?

I have this code attached to a model, the model is meant to turn and face the player wherever they go. But the enemy seems to bend backwards if the player gets close, how can I make him turn only?

 var walkSpeed: float = 3; // Walk Speed
 var runSpeed: float = 6; // Run Speed
 var footsteps : AudioClip; //Walking SFX
 var Stamina = 100; //Stamina
 
 private var chMotor: CharacterMotor;
 private var tr: Transform;
 private var dist: float; // distance to ground
 
 function Start(){
     audio.clip = footsteps;
     audio.loop = true;
     
     chMotor = GetComponent(CharacterMotor);
     tr = transform;
     var ch:CharacterController = GetComponent(CharacterController);
     dist = ch.height/2; // calculate distance to ground
 }
 
 function Update(){
     var vScale = 1.0;
     var speed = walkSpeed;
 
     // If a WASD button has been pressed, play sound
     if (Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.A) || Input.GetKeyDown (KeyCode.S) || Input.GetKeyDown(KeyCode.D))
     {
         // Only start playing, if the audio hasn't been started yet
         if(!audio.isPlaying)
             audio.Play();
     }
     // If none of the WASD buttons are pressed, stop sound
     else if(!Input.GetKey (KeyCode.W) && !Input.GetKey (KeyCode.A) && !Input.GetKey (KeyCode.S) && !Input.GetKey(KeyCode.D))
         audio.Stop();
                 
     if (chMotor.grounded && Input.GetKey("left shift") || Input.GetKey("right shift")){
         speed = runSpeed;
     }
     
     chMotor.movement.maxForwardSpeed = speed; // set max speed
     tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
 }
Comment
Add comment · Show 2
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 aldonaletto · Oct 12, 2012 at 11:41 PM 0
Share

This looks more like the player script! Is this the right script?

avatar image Konkor4 · Oct 13, 2012 at 07:37 AM 0
Share

Yeah you was right, I must of posted the wrong code whilst half asleep... It won't let me edit so I'll re upload as a new answer.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Raycast Rotate Help 1 Answer

Weird rotation shapes 1 Answer

Rotating to -forward goes upside down 1 Answer

Make player move in local direction he is turned. 1 Answer

How do I make my player face the way he walks? 2 Answers


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