Search Unity

Physics gone wild ...

Discussion in 'Scripting' started by StephanA, Mar 26, 2008.

  1. StephanA

    StephanA

    Joined:
    Mar 26, 2008
    Posts:
    3
    Hi Unitymaniacs!

    i am working on a sports game ( handball ). the deal is to throw a ball into a goal. on the 7 meter mark acts an animated goal keeper.

    now everything went fine for about 2 minutes or so ... after that the physics is getting crazy. the ball flies trough all objects.

    i am positioning the ball at position/rotation of the camera. then i add velocity to throw the ball.

    Code (csharp):
    1.  
    2. function throw_ball(){
    3.                 ball.rigidbody.velocity = Vector3.zero;
    4.         ball.rigidbody.angularVelocity = Vector3.zero;
    5.        
    6.         ball.transform.position = camera.main.transform.position;
    7.         ball.transform.rotation = camera.main.transform.rotation;
    8.          
    9.         ball.transform.eulerAngles.x -= 10; //
    10.                        
    11.         ball.rigidbody.velocity = Camera.main.transform.TransformDirection(Vector3(0,2,12));
    12. }
    13.  
    watch my game at action:
    http://www.hbl-duell2.de/~hr-konter
    (use demo/demo for login and password)

    any ideas while this works fine for some time and then getting crazy?

    thanks for support

    Stephan
     
  2. BlueMumm

    BlueMumm

    Joined:
    Feb 7, 2008
    Posts:
    43
    Cant look at the demo nothing responds when its done loading
     
  3. Mortoc

    Mortoc

    Joined:
    Nov 3, 2006
    Posts:
    50
    Same here...
     
  4. Obscurity

    Obscurity

    Joined:
    Nov 13, 2007
    Posts:
    203
  5. HJPuhlmann

    HJPuhlmann

    Joined:
    Oct 18, 2007
    Posts:
    47
    I see no problems within 2 min. After the restart of a game, then the ball went crasy. But I do not point why ..... :cry:
     
  6. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    [a possible answer] are you calling throw_ball in update? update is executed every frame. at high frame rates your velocity could increase fast. calling it in fixedupdate will execute every physics time step and will be frame rate independent.
     
  7. HJPuhlmann

    HJPuhlmann

    Joined:
    Oct 18, 2007
    Posts:
    47
    mmmhhh .... the same level and view .... not probably. Unless the engine runs then faster (fps) .... Is that possible? I hope the answer is no.
     
  8. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    well yes it is possible. framerate fluctuates. even on the same machine. if i have another app open in the background (or say some system process is happening) my fps most likely will be lower than if i quit that app or the process ends. anything framerate dependent would be affected. fixed update lets you avoid this by executing in a fixed time interval. so, it's independent of frame rate and always consistent.

    i misread the original post as adding velocity rather than just setting it. so it's probably something else in this case. tough to say without seeing more of the project.