• 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 crjowen1993 · Jan 25, 2019 at 06:50 PM · instantiatetransform.forward

Instantiate / transform.forward not working properly,Instantiate - Transform.position + Transform.forward gets further away if I am moving? Why?

Instantiate (enemies [EnemyIdentity], transform.position + transform.forward * 2 + transform.TransformPoint (0, 0, 0), Quaternion.Euler(transform.rotation.x,transform.rotation.y,transform.rotation.z));

For some reason, when I am holding in w (run forwards), the object being instantiated spawns much further away than when I stay still. Why is this?

Thanks in advance.,Instantiate (enemies [EnemyIdentity], transform.position + transform.forward * 2 + transform.TransformPoint (0, 0, 0), Quaternion.Euler(transform.rotation.x,transform.rotation.y,transform.rotation.z));

For some reason, when I am holding the w key (forwards) and my player is running, the enemy that is spawned is spawned much further away than if I am not pressing anything. Why is this?

Thanks in advance.

Comment
Add comment · Show 2
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 crjowen1993 · Jan 25, 2019 at 06:58 PM 0
Share

I removed transform.TransformPoint (0, 0, 0) which seemed to work for some reason. However, the instantiated object still isn't facing the same way as my character.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jan 27, 2019 at 02:39 AM

You have a lot misconceptions here.Like DCordoba mentioned above transform.TransformPoint (0, 0, 0) is exactly the same as transform.position. Since you use both and add them together you get twice the offset from the world origin.


Second is this line make no sense whatsoever:

 Quaternion.Euler(transform.rotation.x,transform.rotation.y,transform.rotation.z)


transform.rotation is a Quaternion and does not represent euler angles. A quaternion is a 4 dimensional complex number system and has the components x,y,z and w. Since we use unit quaternions to represent rotations / orientations those are in the range of -1 to 1. Quaternion.Euler on the other hand expects 3 euler angles in degree (0 to 360 or -180 to 180) and will create a quaternion from those.


If you want the instantiated object to be rotated exactly the same as the object that instantiates the object, just pass transform.rotation as rotation. So just do:

 Instantiate (enemies [EnemyIdentity], transform.position + transform.forward * 2, transform.rotation);


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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

122 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 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

Trouble with rb.Addforce(transform.foreward) 3 Answers

Fire bullet in camera direction problem 3 Answers

2D tank firing projectile in C# - transform.foward doesn't seem to work 1 Answer

Checking if object intersects? 1 Answer

how do I make it so my building prefab instantiates only once 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