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 Jan 16, 2018 at 02:13 AM by matthrewp for the following reason:

This question is no longer relevant.

avatar image
0
Question by matthrewp · Nov 08, 2016 at 03:10 PM · rigidbodyscript.modellookrotation

Rotate pieces of model to look at player

I have a artillery-type model in my game, and i want one group of pieces to rotate left and right to look at the player, and a group inside that group to also rotate up and down to point at the player. I have a script made, but it won't let me pick the right direction to be forward.

 using UnityEngine;
 using System.Collections;

 public class Aim : MonoBehaviour {

     public Vector3 LeftRightForward;
     public Vector3 UpDownForward;
     public bool LeftRight;
     public bool UpDown;
     GameObject Player;

     void Start()
     {
         Player = GameObject.Find("Player");
     }

     void Update()
     {
         if (LeftRight)
         {
             GetComponent<Rigidbody>().rotation = Quaternion.LookRotation(new Vector3(Player.transform.position.x, transform.position.y, Player.transform.position.z) - transform.position, LeftRightForward);
         }
         if (UpDown)
         {
             GetComponent<Rigidbody>().rotation = Quaternion.LookRotation(Player.transform.position - transform.position, UpDownForward);
         }
     }
 }

(The reason for so many public variables is so i could find out which direction was the right forward for the model from the editor.)

Here are pictures of the model: Rotate Left-Right Rotate Up-Down Base All Does anyone know what is wrong?

P.S. The Up-Down and Left-Right have the script attached with the correct bool set to true. These pictures are slightly old

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

1 Reply

  • Sort: 
avatar image
0

Answer by oren_danniel · Nov 08, 2016 at 03:20 PM

Have you tried:

 //for instant rotation 
 transform.LookAt(transform); 
 //smooth rotation
 transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(target.position - this.transform.position), speed * Time.deltaTime);//in here you can edit the vector target so it would work only on the x axis for exmp



Comment
Add comment · Show 6 · 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 matthrewp · Nov 08, 2016 at 03:27 PM 0
Share

the wrong side of the model faces the player when I do this. Is there a way to fix that?

avatar image oren_danniel matthrewp · Nov 08, 2016 at 07:51 PM 0
Share

Which axis X, Y, Z? What are you using lookAt or rotation?

Regardless try to put a $$anonymous$$us on the wrong side!

avatar image matthrewp oren_danniel · Nov 08, 2016 at 08:16 PM 0
Share

I'm doing LookAt(), and i have tried every combination of 1's and -1's in the new Vector3 as the second field in the LookAt(transform, Vector3 up) and nothing points my model in the right direction. Here is a video and picture showing what happens and what I want to happen:
Picture Video: https://drive.google.com/open?id=0B_HzgsC9lP3nQXBXNU1NaVVtQjQ

Show more comments
Show more comments

Follow this Question

Answers Answers and Comments

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

Related Questions

How do I stop my player from going through the platform? 1 Answer

Workaround to Non-Convex mesh colliders with non-Kinematic RigidBodies? 1 Answer

turn of the object behind the auxiliary quaternion lerp 1 Answer

LookAt rotate around X 1 Answer

How do I Add Speed to Instantiated Object. 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