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 Mythix · Aug 08, 2011 at 09:05 AM · rotateorientation

Inheriting orientation from collision

Hi there,

I have my player who is moving in a straight line. When he hits a "waypoint" I want him to rotate to the same orientation as the waypoint and continue to move forward in his new orientation until he hits another waypoint.

I have my player moving and writing to the log when he hits a waypoint, but I don't know how to get the orientation information from the waypoint and then apply it to the player.

When I set out to do it I thought it would be simple, but it's not... :(

I'm very new to Unity and scripting, so I would really appreciate some help.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Waz · Aug 08, 2011 at 09:14 AM

Assuming the direction of waypoint2 is towards waypoint3, you can use:

player.transform.rotation = Quaternion.LookRotation(waypoint3-waypoint2);

Or even just player.transform.LookAt(waypoint3).

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 Mythix · Aug 08, 2011 at 09:37 AM 0
Share

Thanks for the help :)

avatar image Mythix · Aug 08, 2011 at 10:54 AM 0
Share

I have set the waypoint as a target variable. Is there a way to change that target to the next target once I have hit one?

e.g. I set the first target to always be "waypoint0". When the player object hits "waypoint0" I want it to change (its) 'target' to "waypoint1"

I was thinking that I could have another variable for the waypoint number, and increment it each time a waypoint is hit. The target would then be ("waypoint" + waypointNumber) sort of thing.

I just don't know how to translate this into working code...

avatar image
0

Answer by Mythix · Aug 08, 2011 at 02:27 PM

OK, so here's what I came up with to get it to work...

 private var target : Transform;
 private var targetWaypoint : String;
 private var wayPointNumber : int;
 var speed : int = 1;
     
 wayPointNumber = 0;
     
 function Update () {
        transform.Translate(0,0,speed*Time.deltaTime);
        targetWaypoint = ("waypoint" + wayPointNumber);
        target = GameObject.Find(targetWaypoint).transform;
        transform.LookAt (target);
     }
    
 function OnTriggerEnter(waypointCollision:Collider){
        if(waypointCollision.gameObject.tag == "Waypoint"){
        wayPointNumber = wayPointNumber + 1;
        }

}

This does what I need, but with LookAt it's snapping from each target to the next. I would love to dampen the LookAt. I have looked at the original script for the camera, but I'm not sure how to work the damping for that into what I have there. I've tried but couldn't get a result...

I just want it to rotate a bit smoother on the Y.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

Event for orientation change done? 1 Answer

How to get my rigidbody character to orient rotation to a game object 0 Answers

How to fix the rotation and Orientation in an object as a Children ? 1 Answer

How to keep character facing 3/4 front when moving right and left in 2.5D game 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