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 /
This question was closed May 13, 2013 at 09:27 PM by Eugenius for the following reason:

Problem was different than the one asked

avatar image
0
Question by Eugenius · May 08, 2013 at 11:50 PM · instantiateinstantiationinstantiating

How to limit the instantiation of a prefab/object?

I will explain this in the best way I can.

I want to be able to instantiate an object(or a prefab) in a certain direction until it collides with a gameobject that has the "Wall" tag. When it hits the "Wall" gameobject I would like it to resize the object so that it will never pass through the wall.

Is this possible in any way? Any tips or hints would be appreciated too!

Thank you, Eugen

Comment
Add comment · Show 1
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 Fattie · May 09, 2013 at 05:38 AM 1
Share

sugges unityGE$$anonymous$$S.com for beginner articles on physics, etc.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Mortoc · May 09, 2013 at 01:49 AM

If you keep track of your "wall" or plane as point-normal, it's really easy (Khan academy link for the math involved). The code would look something like this:

 Vector3 wallToObject = wall.position - object.transform.position;
 float dot = Vector3.Dot(wallToObject, wall.normal);
 
 if( dot > 0.0f )
     // object has passed the wall this frame, move it back and instantiate your collision object


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 Eugenius · May 12, 2013 at 09:04 PM 0
Share

I'm not sure that is what I'm looking for.

I am normally instantiating more than 1 object (at least 2, sometimes even 10 instances) and the Dot gives me vector3 coordinates while at any given time I am going to be interested in the y or x position. The "z" does not matter for the project I am currently building.

Any work arounds for this?

I tried adding a collider on the prefab that I am creating instances of and a script that tells it to stop when it hits the top but it doesn't seem to work.

Edit: I managed to get it to see the collision by adding a rigidbody (my bad) still not working but I am going to ask another question because the problem changed.

EDIT 2: Your script almost worked, but I managed to fix it by simply conditioning it to a variable in a separate script! $$anonymous$$arked as correct as I probably would have solved it by using this as well.

Follow this Question

Answers Answers and Comments

14 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

Related Questions

Cloud objects not instantiating (Oh no!). 0 Answers

Why is it important to create an empty gameobject for my prefabs? 0 Answers

Instantiate as child of a to-be-instantiated list item 1 Answer

Instantiating in Awake() v Setting up prefab instances in Editor performance difference? 1 Answer

Checking if object intersects? 1 Answer


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