Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Mateusz-Armir · Oct 13, 2018 at 08:34 PM · collidersfollowoffsetfollowing

Target a point in space relative to gameObject

Hello


I am making a demo of a sci-fi game in space.


I have a missile, that flies to certain target. I also have a spaceship GameObject. Inside this spaceship GameObject there is a ShipBody with Box Collider, and this Collider is the target for the missile. When I fire the missile it aligns to the target and moves slowly to it - this works fine for me. But after launching multiple missiles at once I saw, that they all fly straight to the center of the ShipBody, and it looks unrealistic. So I made a function that when a missile is acquiring target it also generates random offset inside the mesh of the Collider, so missiles seem to hit different spots of the ShipBody - and it works fine.


The problem is when I rotate the ship. It still flies to the position+offset, but it do not recognize the rotation of the main object. I hope image will clarify this.


I dont want to do this by just creating empty GameObject inside SpaceShip - what if there will be hundred missiles and dozens of ships. I dont want to litter the scene with useless GameObjects. I will do this, if this is the only way, but If there is more elegant one, I will try to implement it.

alt text

effect.png (498.7 kB)
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
1
Best Answer

Answer by toddisarockstar · Oct 14, 2018 at 05:18 AM

you are going to need to use local position. local positions are relative to a parent object's rotation and position. if you dont want to use empty objects as markers then you can use transform.InverseTransformPoint to store a local position relative to the ship.

you can then use transform.TransformPoint to get the point back with consideration of the ships position and rotation. transform.InverseTransformPoint

transform.TransformPoint

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 Mateusz-Armir · Oct 14, 2018 at 10:07 PM 0
Share

Can you tell me how my operations should commence?


I have:

GameObject ship

Vector3 hotspot - this is my offset from the ship center

GameObject cube - cube for reference inside the ship. Vector3 identical to cube.transform.position should be the outcome of the operation.


What should I do to calculate the outcome?

avatar image Mateusz-Armir · Oct 14, 2018 at 10:41 PM 0
Share

transform.TransformPoint(hotspot) did the thing!

avatar image
0

Answer by Lagger625 · Oct 14, 2018 at 05:51 AM

You can multiply the random offset by the spaceship transform.right, transform.up and transform.forward every frame to get an updated offset. Those values consider the gameObject rotation.

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 Mateusz-Armir · Oct 14, 2018 at 09:56 PM 0
Share

Please, can you tell me how to multiply this offset with those vectors?

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

94 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

Related Questions

My collider is offset from where it appears in the scene editor when I'm in gameplay mode 1 Answer

Camera dont move whit Smooth Follow 2D 0 Answers

Animation Stops Unexpected. (Script included) 0 Answers

How to make an enemy chase you and catch you when close (like slendytubbies) 0 Answers

How do I create AI with a good side and evil side? 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