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 IBone · Jan 14, 2013 at 06:00 PM · transformpositiontarget

Set Y position same as another object

In my game you are trapped in a room with a lot of hills and an enemy that acts like a weeping angel (for those that don't know, it is a little bit like slender man). The enemy script works fine, but when the player goes onto a hill the enemy will go straight through the hill rather than going up it to follow the player. Is there any way to fix this? I would be happy with the enemy just being set to the same Y axis as the player, but if you know of a better way to get the enemy to actually go up the hill, that would be awesome. Here is my script for setting the y axis of the enemy:

 transform.position.y = 11;

Thanks in advance for any 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
Best Answer

Answer by Lovrenc · Jan 14, 2013 at 06:05 PM

Add "terrain" tag to your terrain.

 var hit : RaycastHit;
 if (Physics.Raycast (transform.position, -Vector3.up, hit, 10)) {
   if(hit.tag == "terrain") {
     transform.position.y = hit.point.y;
   }               
 }
Comment
Add comment · Show 1 · 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 IBone · Jan 14, 2013 at 07:14 PM 0
Share

Thanks, this worked perfectly. Gugu's answer would have worked, as I said I wouldn't $$anonymous$$d if it floated. But after a bit of editing to get this script functional with my script it looks amazing. Thanks again.

avatar image
0

Answer by gugu6897 · Jan 14, 2013 at 07:05 PM

Do this in enemy script:

 transform.position.y = playerscript.transform.position.y;

In place of 'playerscript' you put the name of the script attached to the player gameObject that you want to use the Y position.

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 Lovrenc · Jan 14, 2013 at 07:08 PM 0
Share

Then the player will sometimes fly around.

avatar image IBone · Jan 14, 2013 at 07:15 PM 0
Share

If I could accept two answers I would, because this also worked for what I asked for. Sorry about that.

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

Rotating Y towards X/Z 1 Answer

Need enemy to follow only active character 0 Answers

Drawing a (debug) line between anchored UI element and mouse? 0 Answers

I need help with the location of instatiated objects on the scene and correct interaction with this 2 Answers

How to move an object to your current positon? 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