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
1
Question by Supershandy · Jun 17, 2012 at 07:43 PM · objectscollisionsrigidbodiesiskinematic

Collsions - Objects just passing through each other

I'm halfway through my Game Production but i'm having trouble with collisions, each object (that I want to collide) has a rigidbody, isKinematic turned off, and a relative force added plus a physics material added to the mesh collider, but whenever I run the program and set it so that a certain amount of objects collide with each other, they just pass straight through each other as if the colliders weren't there.

However my bullet script works fine when detecting that it has hit something, but I thought the Unity Engine was supposed to be able to handle this kind of stuff with world collisons without the need for extensive coding.

Here is my script so far (for the objects I want to collide)

pragma strict

var object : GameObject;

function Start()

{

for (var i : int = 0; i < 100; i++)

 {
             var AsteroidSpeed : Vector3 = Vector3 (0,0,1);
             var position : Vector3 = Random.insideUnitSphere * 500;
                         transform.position.x = position.x;
                         transform.position.y = position.y;
                         transform.position.z = position.z;
             var rotation = Quaternion.Euler ( Random.Range (0, 360), Random.Range (0, 360), Random.Range (0, 360) );
             
             Instantiate (object, position, rotation);
             rigidbody.isKinematic = false;
             rigidbody.detectCollisions = true;
             rigidbody.MovePosition ( rigidbody.position + AsteroidSpeed * Time.deltaTime);
             yield WaitForSeconds (0.0001);
             
 }

}

Any help would be much appreciated as I'm banging my head against the wall here

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 whydoidoit · Jun 17, 2012 at 07:51 PM 0
Share

Have you set the collision mode to continuous dynamic?

1 Reply

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

Answer by aldonaletto · Jun 17, 2012 at 08:14 PM

What do you expect this code to do? It actually repeat 100 times a weird sequence: generate a random point inside a sphere of radius 500 centered at (0,0,0), move its owner object to this random point, rotate it randomly, instantiate a clone of object at this position and let it alone there, then move the owner object a little in the Z direction, wait for the next frame and repeat the sequence.
If you want to generate 100 asteroids at random positions and moving to random directions, use a script like this attached to some scene object (not the asteroids!):

var object: GameObject; // drag asteroid prefab here var speed: float = 10; // set the asteroid speed

function Start(){ for (var i : int = 0; i < 100; i++){ // create an asteroid at random position and direction: var position : Vector3 = Random.insideUnitSphere 500; var rotation = Random.rotation; var asteroid: GameObject = Instantiate (object, position, rotation); // set the asteroid velocity to its forward direction: asteroid.rigidbody.velocity = asteroid.transform.forward speed; } }

Comment
Add comment · Show 5 · 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 whydoidoit · Jun 17, 2012 at 08:20 PM 0
Share

Good point :) I should have read the code better!

avatar image Supershandy · Jun 18, 2012 at 09:27 AM 0
Share

When you say scene object am i to assume that you mean an empty Gameobject? Also what about the original question where i'm having problems with the asteroids passing through each other rather then colliding with each other and moving off in a different direction as I want them to do that as well as bounce off a perimeter sphere, also thanks for the revised code, will test it after work :)

avatar image aldonaletto · Jun 19, 2012 at 04:22 AM 0
Share

The script may be attached to an empty object, or the camera, or any other object - except the asteroids, because this would crash Unity (each new asteroid would generate 100 new ones, and each of them would generate another 100, and so on).
A common problem is the discrete nature of collision detection: when a rigidbody moves too fast, it can be before an obstacle in one physics cycle and after it in the next, what misses the collision.
As @whydoidoit suggested, you could try continuous collision detection, but for 100 rigidbodies this would kill your framerate.

avatar image Supershandy · Jun 19, 2012 at 08:24 AM 0
Share

The script worked perfectly thank you, on the subject of collisions i worked out the problem, i tried continous collision detection and that didn't work, i had to set the rigidbody to "convex" but since that only works with upto 255 triangles it wouldn't recognise a collision, using a primitive collider however solved the problem :) even with 100 asteroids :p

avatar image Mizuho · Jun 19, 2012 at 08:27 AM 0
Share

@Supershandy: Now you just have to accept his answer :D.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How to snap object to terrain after already placed in scene? 3 Answers

Solid objects 1 Answer

How do I make and object move then respawn at it's start point and move back again in an infinite loop? 3 Answers

Multiple Collisions Within Different Objects 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