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 Pixeye · Jan 28, 2011 at 10:20 AM · raycastarraygameobjectslinkingchain

Game Object Chains

Hi. Im trying to make gameobject-chain system.

Ill try to explain what i mean. For example i have power plant object. If other object is in power plant radius then it's active. If third object connected to second object that is connected to power plant - third object will be active. And so on.

I tried to do that with raycast hit, collisions but system doesnt work correctly.

var linked = 0; var number = 100000; var pos = Vector3[];

 function Awake()
 {
 pos = new Array(4); ( something like that ) 

 }

 function Update()
 {
 checkForLink();
 }

 function checkForLink()
 {
 pos[0] = Vector3.up
 pos[1] = -Vector3.up
 pos[2] = Vector3.right
 pos[3] = -Vector3.right

 var hit = Raycasthit (blablabbla)
 var hit_range = 32; // 

 for (var i=0; i<4; i++)
 {
 if (phisics.raycast(transform.position,pos[i],hit,hit_range)
 {
 if (hit.collider.tag=="base"&&link==0)
 {
 var ob: GameObject;
 ob = hit.collider.gameobject;
 if (ob.GetComponent(script).link==1&&ob.GetComponent(script).number<number)
 {
 link = 1;
 number = ob.GetComponent(script).number + 1
 }
 }
 }
 }


 }

some pseudo code to understand what i did. I managed to make system that will check for object link to the power plant, but i dont know how to make check in situations when for example some objects are sticked together but are not linked to powerplant - so they must be inactive. Other situation is when i need to unlink object if there are no objects to link with in right left up down sides. Ofcource I made some scripts to handle that but they conflicted with first checklink script so sometimes an object that was linked "flipped" from linked status to unlinked when he shouldnt.

Can anyone please help with that kind of algorithm? I understand scheme but cant properly code it in unity.

PS ( its a pseudo2d game) There is a real example of what i need in flash "The Space Game" or in SimCity, where you must build pipes to connect pump-house with other houses.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Jan 28, 2011 at 11:44 AM

For such a case i would recommend Physics.OverlapSphere. That way yon don't have gaps between your rays and the overall math for the physics system is a lot easier.
Well, the connection problem. You could setup the whole "net" and then doing some kind of A* algorithm but i think that's too complicated for such a case.

It's better to have some kind of a "LinkedTo" variable that holds a reference to the node itself is connected to (assuming there's always just one source). Every node checks for neigbours and check their linkedto variable. If there's something referenced (not null) we set our LinkedTo variable to this node. A Special case would be the powerplant of course.

It sounds to me like the Onslaught gamemode in UT2004 or like in the game Perimeter, am i right?

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 Pixeye · Jan 28, 2011 at 11:48 AM 0
Share

Yes!) Like in Perimeter.

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

No one has followed this question yet.

Related Questions

Checking Array of GameObjects if it contains selected GameObject (C#) 1 Answer

After days of looking for solutions, what's wrong with my array script? 2 Answers

Creating a 2d array of gameObjects 2 Answers

Multiple Fire Points 2 Answers

Waypoint problems 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