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 /
avatar image
0
Question by FuryFight3r · Mar 30, 2018 at 07:21 AM · directionrotate objectfacing

Slerp object in direction of traveling

Hi there guys, i'm having an issue trying to figure out how to keep an object looking the direction it is heading, I have some boats that float around a scene going to and fro random waypoints, i did have the boats looking into the direction they were heading when the waypoints just went up by one number ie, start at 0, next is 1, next is 2, but now that they are randomised, I don't know how to grab that random number and face toward it.

This is the current scripting I have for my boats, the Quaternion Vector3 parts of the script I had removed due them them not being able to identify that said randomised number (or atleast im unsure of how to indentify it within a Quaternion Vector Slerp).

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class boatScript : MonoBehaviour {
 
     public Transform[] target;
     Transform newTarget;
     public float rotationSpeed = 5;
     public float speed = 1;
     public float accuracyWP = 10;
     bool isMoving = false;
 
     void Start () {
         
     }
 
     void Update () {
         if (!isMoving)
         {
             newTarget = target[Random.Range(0, target.Length)];
             isMoving = true;
         }
 
         transform.position = Vector3.MoveTowards(transform.position, newTarget.position, speed * Time.deltaTime);
         
         //Needs Rotation Here
 
         if (transform.position == newTarget.position)
         {
             isMoving = false;
             
         }
 
     }
 }
 
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

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

Answer by x4637x · Mar 31, 2018 at 08:08 AM

Insert this after line 25 : transform.LookAt(newTarget);

Comment
Add comment · Show 4 · 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 FuryFight3r · Mar 31, 2018 at 09:01 AM 0
Share

Thank you for the reply, is there anyway i can add a Slerp to this function?

avatar image x4637x FuryFight3r · Mar 31, 2018 at 09:27 AM 0
Share

Take a look at Vector3.Slerp, maybe this is what you want.

avatar image FuryFight3r · Mar 31, 2018 at 09:45 AM 0
Share

i think more in what i am after is a Quaternion Slerp sorry, im very new, still looking at API's to understand how it works.

avatar image x4637x FuryFight3r · Mar 31, 2018 at 11:07 AM 0
Share

Try using this ins$$anonymous$$d :

line 26 : transform.rotation = Quaternion.LookRotation(Vector3.RotateTowards(transform.forward, newTarget.position - transform.position, rotationSpeed * Time.deltaTime, 0.0f));

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

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

Related Questions

How do I rotate a Gameobject in the direction of its motion? 1 Answer

Control object yaw by two axis 1 Answer

Change Facing Direction 4 Answers

How do I move a CharacterController type in the direction it's facing? 1 Answer

How to check in which direction an object is facing? 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