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 Yinoguns · Sep 03, 2013 at 04:10 PM · rotationplayerrotatefollowface

Rotate to face player, drunk issues

Hello, been Unity Scripting for a while but still trying stuff out, right now I am trying to make an object turn and move to the player.

My main issue is the object will turn to face the player's starting position, but not when I move the player through typical control as a player would be.

If I move the player through the editor it works fine, turning and moving. I have a feeling this is some issue with me using Pos.position and not a Vector3, see the code.

My other issue is when I move the player which is a typical FPS player controller, the object following it goes at wierd angles as if it is drunk.

Here is the code:

 using UnityEngine;
 using System.Collections;
 
 public class RemoteMovement : MonoBehaviour {

     public Transform PlayerPos;
     
     public float strength = 1f;
     float str;
     
     Quaternion targetRotation;
 
     // Use this for initialization
     void Start () {
     
     }//START
     
     // Update is called once per frame
     void LateUpdate () {
         
         
         
         if(    Input.GetKey("i")    ){
             
             transform.Translate( transform.forward*0.05f);
             
         }//if
         
         
         targetRotation = Quaternion.LookRotation (PlayerPos.position - transform.position);
           str = Mathf.Min (strength * Time.deltaTime, 1);
            transform.rotation = Quaternion.Lerp (transform.rotation, targetRotation, str);
         
         Debug.Log("Player Pos: X;"+PlayerPos.position.x+" Y;"+PlayerPos.position.y);    
         
         Debug.Log("targetRotation: "+targetRotation);
         
         transform.Translate( Vector3.forward*0.05f);    
         
         
     }//UPDATE
 }//CLASS

Comment
Add comment · Show 4
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 fafase · Sep 03, 2013 at 04:19 PM 0
Share

I remove the answer but you still need to change for tranform.forward, or your guy will only move in the same direction Vector3.forward.

avatar image Yinoguns · Sep 03, 2013 at 04:24 PM 0
Share

Fair enough, but currently my only issue is rotating without going drunk, and rotating to a moved player or object through scripts, not if I move it through the editor.

avatar image fafase · Sep 03, 2013 at 04:28 PM 0
Share

There is a part about rotation there :http://unitygems.com/basic-ai-character/#Start

avatar image Yinoguns · Sep 03, 2013 at 07:51 PM 0
Share

Ok I have been looking at this stuff, it makes a decent amount of sense but when I implement it, something doesn't work.

$$anonymous$$y following object turns, but never all the way to the player and still only when I move the player through the editor.

 public Transform PlayerPos;
 
 
 
 
 Vector3 newRotation = Quaternion.LookRotation(PlayerPos.position - transform.position).eulerAngles;
 newRotation.x = 0;
 newRotation.z = 0;
 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(newRotation), Time.deltaTime);

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

16 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 avatar image avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

Player rotating in direction of joystick doesn't work, why?,Rotate Player in direction of Joystick has too little impact 0 Answers

Rotate the player to face where the mouse is pointing 3 Answers

Rotate character acording to buttons pressed 0 Answers

I need animate arms with script when I rotate my character like in Escape of Tarkov 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