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 Zhapness · May 22, 2011 at 12:26 AM · instantiatevector3distanceareazone

Instantiating inside an area only.

Hi In my game players can instantiate objects, but they should only be able to do it inside of an area. alt text

I only want to be able to instantiate objects inside of that box

I have tried using Vector3.distance, but that will only use a single int and not like a x and y distance.

Any suggestions?

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 Eli-Davis · May 22, 2011 at 12:30 AM 1
Share

Can the player only instantiate when there in the box, or do you mean that the player can only instantiate the item into the box?

avatar image Zhapness · May 22, 2011 at 01:00 PM 0
Share

sorry i forgot to say that i use Raycasting for instantiating the objects at mouse position. players should also be able to instantiate objects when standing outside of the area.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Justin Warner · May 22, 2011 at 01:26 AM

Get the coordinates of the corners, have the instantiate check before it actual instantiates if the X/Y/Z's are within bounds... We kinda did a project like this in CS class. But yeah, just check it before, if it passes all tests, than instantiate, if not, then ignore.

So, if spot to spawn is above this and is below this, and is on this side and this side of this of both the x and z, then spawn, else, dont do anything =).

 if(X <= __ && Y <= __ && Z <= __ && X >= __ && Y >= __ && Z >= __)
 {
     //Spawn
 }
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 Zhapness · May 22, 2011 at 01:03 PM 0
Share

Ok nice thanks, but is there any way to get the corner positions from a script? because in my game i will have many areas like this one in different sizes :)

avatar image
0

Answer by Muuskii · Jul 21, 2012 at 01:44 PM

Try creating a trigger collider to define where you are allowed to instantiate objects inside and then in a script that has a reference to that collider use this:

 if(myCollider.bounds.Contains(ray.GetPoint(hitdistance) ) )
 {
     //spawn
 }

Bounds.Contains

This works with box colliders, sphere colliders, etc, etc.

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

Distribute terrain in zones 3 Answers

Add 0.5f to Vector.Right on next instantiated object ? 1 Answer

Objects spawning in relation to resolution 1 Answer

Find a position by knowing the directionVector and the distance to this point 1 Answer

Creating more objects the closer you get 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