Search Unity

Car Damage by Speed?

Discussion in 'Scripting' started by grobm, Oct 22, 2006.

  1. grobm

    grobm

    Joined:
    Aug 15, 2005
    Posts:
    217
    I am porting a game design from Torque to Unity. I am amazed on how fast I can do it except for scripting the interaction I need for damage. I would like to have a Car receive damage by the speed it hits any collider in the provided it exceeds a specific speed value. Example: Car moving at 10 mph will get damage of .1... have the value be ignored unless it exceeds a value of 1.

    I modified the FPSPlayer.js so that it will work with the Car.js in the RaceDemo. The issue I have now is how to get the damage to register by impact.

    Any help would be great. I am still evaling the game development environment... but I plan to buy it once the time is up. Any help would be very helpful to my game.
     

    Attached Files:

  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  3. grobm

    grobm

    Joined:
    Aug 15, 2005
    Posts:
    217
    Attached is my updated code... but the issue I have right now is any collision triggers the damage if it is a Blockcollider. I will look into the relativeVelocity and see if I can get it to work.

    Thanks,
     

    Attached Files:

  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Code (csharp):
    1.  
    2. function OnCollisionEnter()
    3. {
    4.         var hit : BoxCollider;
    5.         var direction = transform.TransformDirection(Vector3.forward);
    6.  
    you are declare a hit variable to an undefined value, then you are trying to use it. Can't do that.

    Take a look at the first sample on the link i posted above. It shows you how to use the OnCollisionEnter function using relativeVelocity to determine if a sound should played.