• 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 Apr 04, 2013 at 11:23 PM by thatanimator for the following reason:

Solved by moving a cube instead, using that as the box collider rather than attaching a box collider to the object and moving it.

avatar image
0
Question by thatanimator · Apr 04, 2013 at 02:31 AM · boxcollider

collider.center = Vector3() in runtime?

Good day! Going to try to keep it short!

Had a game prototype working on my pc with a bunch of cubes moving down a level. All of them had a box collider which animated along with them as they moved. This turned out to be way too heavy for iOS and I had to think of another way for my colliders to move along with my boxes (over 2-300 of them at a time!).

The way I found works and I can have 2-300 boxes all individually animated and moving along with their colliders.

The problem is that as a box lands on a marker that the player can place, it is supposed to get assigned to a target, which the player later can destroy. This all worked the way I wanted it to, before doing this performance fix - or whatever you may call it.

The way I move the collider now is by using the collider.center = Vector3(); function and it works, it moves the collider.. I think?

alt text

From top to bottom the images are:

  1. The cube leaves it's previous square, the collider hangs around just a bit longer.

  2. The collider moves into place in the square infront. If there is a marker there, the cube should be added to the target variable.

  3. The cube mesh and animation land on the square where the collider is. In the game, this would be the time where you can trigger the mark you placed to destroy the cube.

  4. But it doesn't work, because the Cube parent actually moves to the square a bit later and it is only then the collision is counted!

If I place the collider in front of the box from the get go, it all works. That signals to me that moving the collider in runtime doesn't actually work? It moves the collider, but the engine still thinks that the colliders actuall position is unchanged.

The hierarchy for this entire setup is:

  • Cube <- Parent game object that handles all scripts and what not*

    Pivot <- A game object with an animation on it, that rotates the child cube mesh - Cube <- Just a mesh, a box

The "Cube" parent object comes in different flavors, this "Cube" is just the default name. It's not as confusing as it might look :)

The script is simple as well. I have to move the Cube parent back and forth because of how I've solved the rotation animation on the cube..it's a bit hacky, but it works - even on the iOS device!

 function Roll(){
 
 gameloopscript = GameObject.Find("GameMaster").GetComponent("gameloopscript");
 var hitbox = gameObject.GetComponent(BoxCollider);
 
     if(rollOK == true){
     transform.Translate(0,0,-1);
     pivot.animation.Play("rollanimation");
     hitbox.center = Vector3(0, 0, 0);
     yield WaitForSeconds(0.75);
     hitbox.center  = Vector3(0, 0, -1);
     }
 }

The question is, Is it possible even, to move the collider in runtime and have it act as it should in its new position? Is it a bug in the engine that even if I move it, it still counts as being where the Cube parent game object is?

As it is now, even if the cube mesh lands on a marker and the collider is there, I cannot destroy the cube since it's not assigned to the target variable until the Cube parent has moved into place.

Thank you! Hope anyone can shed some light on this fairly silly problem! If not, any other ideas on how to do this? :) Thanks!

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 thatanimator · Apr 04, 2013 at 02:39 AM 0
Share

I will try to add another cube with a box collider and move that cube rather than just the collider. Should work, but it will add another parent to the Pivot and Cube mesh which might mess about a bit in the scripts a bit since they call for the parent some times.

Still, if anyone knows why the moving of the center of a collider stops it from acting right please tell me! :)

0 Replies

  • Sort: 

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

10 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

Related Questions

'center' is not a member of 'UnityEngine.Collider'. 2 Answers

Box collider not lining up with box mesh? 1 Answer

Invisible barrier transform.Translate error 1 Answer

Object flips 90 degrees when I add a box Collider - strange 0 Answers

Getting bounds of submeshes 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