Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Destroying Projectors.

Discussion in 'Editor & General Support' started by shawnpigott, Apr 6, 2006.

  1. shawnpigott

    shawnpigott

    Joined:
    Sep 28, 2005
    Posts:
    262
    How do you destroy a projector?

    I am working on a billiards style game and I added the 'Blob-Shadow' to the balls. I created a very simple script to attach the shadow to the ball.

    Code (csharp):
    1.  
    2. var presentposition : Rigidbody;
    3.  
    4. function Update () {
    5.                 transform.position.x =  presentposition.transform.position.x;
    6.                 transform.position.z =  presentposition.transform.position.z;
    7. }
    8.  
    I couldn't use parenting because that resulted in the shadow rotating with the balls. When the balls go in the pockets I destroy them or else the shadows continue drifting across the table as the balls fall to infinity. I tried to destroy the 'Blob-Shadow' projector but it doesn't seem to work.

    Code (csharp):
    1.  
    2. function Update () {
    3.     if (transform.position.y < -10) {
    4.         Destroy (gameObject);
    5.     }  
    6. }
    7.  
    Suggestions would be appreciated.
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,732
    Seems like you are checking the y position of the projector instead of the object you are following.
    Maybe you wanted to do this instead?

    Code (csharp):
    1.  
    2. function Update () {
    3.    if (presentposition.transform.position.y < -10) {
    4.       Destroy (gameObject);
    5.    }    
    6. }
    7.  
     
  3. shawnpigott

    shawnpigott

    Joined:
    Sep 28, 2005
    Posts:
    262
    I see your point. I was checking the y position of the projector in order to determine when the ball had fallen through the holes and past the table but the projector is not falling so it will never reach the -10 to destroy.

    Thanks.

    A second question...
    This game is another level to a 'Shooter' style game I have been developing for people with disabilities. They control rotation of the camera in the centre of the table and fire 'Cue Balls' to make shots. The cue balls disappears 5 seconds after the shot so that things don't get crowded. I'm using the 'shootball' script from the playground scene to fire the cueball.
    The problem is that I haven't been able to create a prefab with the cueball and a 'Blob-Shadow' that works properly.
    The 'cueball' fires and intereacts but the shadow doesn't seem to attach to the new 'cueball'. As I stated above I can't parent the shadow to the ball as then it would rotate and the effect would be lost.

    Suggestions?
     
  4. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    One thing to be aware of making a pool-like game or level, I was also trying to make a similar game where you shoot balls to knock other balls off a table, but there is a weird bug with Unity's physics engine that prevents a ball from moving in a straight enough line for this kind of game _unless_ you basically kill all friction on the cue ball. Your ball will veer way too much so it wont hit what your player aimed at. But killing the friction also makes it look and act horrible.

    The discussion is here:
    http://forum.otee.dk/viewtopic.php?t=1434

    It may not be an issue with what you are doing but I'd though I'd let you know before you spent hours banging your head to figure this out ;) I actually had to kill my game project because of it.

    -Jeremy
     
  5. shawnpigott

    shawnpigott

    Joined:
    Sep 28, 2005
    Posts:
    262
    Luckily I'm not shooting for anything that needs to be very realistic. The main goal is for the people playing the game to knock the balls off the table. I have it set up so that different people control different aspects of the shot. Otherwise it would be too challenging for one of them to move, set the power and shoot the ball.

    Although not perfect yet, I have had reasonable sucess with the ball and wall interactions. My main physics problem is that everything seems to move in slow motion (about half speed) after the collisions and that the cue ball bounces too high into the y axis sometimes.

    I think I may be able to solve my Shadow problem if I only use one Cue Ball and I don't try to create a new one each time. That way I can set up the shadow correctly. I haven't had a chance to look at the script though and see how to modify it.

    Thanks for you thoughts.
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,732
    Maybe you should also copy the whole position vector3 instead of just x and z.

    Code (csharp):
    1.  
    2. function Update () {
    3.   transform.position =  presentposition.transform.position;
    4. }
    5.  
     
  7. shawnpigott

    shawnpigott

    Joined:
    Sep 28, 2005
    Posts:
    262
    I didn't copy the y so I could adjust the size of the shadow. In any event, it all seems to be working now. Two bits would improve the game though.

    1. I would like to damped the positive y values of the physics so the balls don't shoot as high off the table after a collision. I works now but it's a little unrealistic.

    2. I have a 'click' sound for the ball collisions but I would like to have a different sound for the wall collisions. Is there a way to distinguish what has collided with what?

    Thanks for the input.
     
  8. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,732
    In OnCollisionEnter you can get to the object you are colliding with.
    You could simply add a couple of tags to all those walls and when collding get the tag and use it to determine which sound to play.

    Why do your balls jump up? Are you using a bouncy physic material?
    Make it less bouncy.
     
  9. shawnpigott

    shawnpigott

    Joined:
    Sep 28, 2005
    Posts:
    262
    I'll look into tags and OnCollisionEnter. It sounds like that should work.

    As for the bounciness, I tried less bouncy and then the balls wouldn't reflect off of the walls. I'll keep working on it. There's a lot of parameters to adjust. I'm sure I can find something that works.

    Thanks for the assistance.