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 Konkor4 · Oct 13, 2012 at 08:25 AM · playerrotateenemynotbend

I want to rotate the model to face player, not bend?

I posted this question about 7 hours ago but included the wrong code, for some reason the post won't edit so I'm posting again. I basically want my enemy model to always face the player but not bend when the player is close.

EDIT: Sorry, what I'm trying to get is I only want the model to rotate left/right, not up and down. The model will rotate so it's facing the sky if I get close, I just want the model to turn around, not bend backwards/forwards.

 var PlayerHealth = 10;    //PlayerHealth Value
 var TakeDamage : boolean; //Damage toggle
 var target : Transform; //the enemy's target
 var moveSpeed = 3; //move speed
 var rotationSpeed = 3; //speed of turning
 var myTransform : Transform; //current transform data of this enemy
 
 function Awake()
 {
     myTransform = transform; //cache transform data for easy access/preformance
 }
 
 //When the player and AI meet enable Damage Toggle
 function OnTriggerEnter(other : Collider){
     if(other.tag == "Player"){
         TakeDamage = true;
     }
 }
 
 //When the player and AI seperate disable Damage Toggle
 function OnTriggerExit(other : Collider){
     if(other.tag == "Player"){
         TakeDamage = false;
     }
 }
 
 function Start()
 {
      target = GameObject.FindWithTag("Player").transform; //Target the player
 }
 
 function Update () {
     //Rotate to look at the player
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
     
     //Move towards the player
     //myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
 
 }
Comment
Add comment · Show 6
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 whydoidoit · Oct 13, 2012 at 08:26 AM 0
Share

I'm guessing that must be some kind of camera perspective bending? It's pretty hard to bend anything in Unity without a plugin.

avatar image Konkor4 · Oct 13, 2012 at 08:30 AM 0
Share

No? The script rotates the enemy model to face the players position, it's just that when the player gets close the model will bend backwards to remain facing the player's position.

avatar image whydoidoit · Oct 13, 2012 at 08:31 AM 0
Share

Could you possible post a screen grab of the effect you are seeing? I would imagine the enemy is probably just getting too close to be realistic - effectively being "within" the player.

avatar image Konkor4 · Oct 13, 2012 at 08:33 AM 0
Share

Here is what it's doing:

http://i.imgur.com/8QL87.jpg

It "bends" backwards so to speak, I guess it's more of a rotation now though.

avatar image whydoidoit · Oct 13, 2012 at 08:35 AM 0
Share

Yeah - that's comedy :) BTW not really bending - that's leaning - but I see your point!

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by whydoidoit · Oct 13, 2012 at 08:36 AM

Just rotate around the Y axis:

   var newRotation = Quaternion.Slerp(myTransform.rotation,
 Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime).eulerAngles;
   newRotation.x = 0;
   newRotation.z = 0;
   myTransform.rotation = Quaternion.Euler(newRotation);
Comment
Add comment · Show 2 · 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 Konkor4 · Oct 13, 2012 at 08:39 AM 0
Share

Ah that works great, thank you!

avatar image whydoidoit · Oct 13, 2012 at 08:43 AM 0
Share

Please "tick" correct answers to keep the board clean

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

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

How to make camera not rotate with player, only move 1 Answer

Rotate object around player when space is pressed. 1 Answer

Camera rotation around player while following. 6 Answers

Script Wont Take away health from my player when hit by enemy bullet. 0 Answers

LookAt once 0 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