Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

sqrMagnitude changed?

Discussion in 'Scripting' started by grosssmutttr, Feb 25, 2016.

  1. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    167
    Hey there,

    I updated Unity and recognized that many things aren't working or the bahaviour changed:

    Code (CSharp):
    1. void OnCollisionEnter2D(Collision2D collision){
    2.         if (collision.relativeVelocity.sqrMagnitude > 50.0f) {
    3.             if(PlayerPrefs.GetInt("SoundAnAus")==1){
    4.                 AudioSource.PlayClipAtPoint(audioHit, transform.position);
    5.             }  
    6.         }
    7.         if (collision.collider.tag != "Damager") {
    8.             return;
    9.         }
    10.         else if (collision.relativeVelocity.sqrMagnitude < damageImpactSpeedSqr && collision.gameObject.name!="Bombe") {
    11.             return;
    12.         }
    13.         else{
    14.             //-> grosse Kraft
    15.             if (collision.relativeVelocity.sqrMagnitude>500.0f) {
    16.                 currentHitPoints-=12;
    17.             }
    18.             //Wenn Object direkt auf Stein trifft -> grosse Kraft
    19.             else if (collision.relativeVelocity.sqrMagnitude>200.0f) {
    20.                 currentHitPoints-=6;
    21.             }
    22.             //Wenn Object direkt auf Stein trifft -> grosse Kraft
    23.             else if (collision.relativeVelocity.sqrMagnitude>100.0f) {
    24.                 currentHitPoints-=4;
    25.             }
    26.             currentHitPoints--;
    27.             if(currentHitPoints>=6&&currentHitPoints<10){
    28.                 spriteRenderer.sprite = damagedSprite1;
    29.             }
    30.             else if(currentHitPoints<6){
    31.                 spriteRenderer.sprite = damagedSprite2;
    32.             }
    33.          
    34.             if (collision.gameObject.name=="Bombe") {
    35.                 Kill ();
    36.             }
    37.             else if (currentHitPoints <= 0) {
    38.                 Kill();
    39.             }
    40.         }
    41.     }
    So I updated Unity from Version 5.2 to 5.3.3 and now the sqrMagnitude has much lower values...

    I also found out that the OnCollisionEnter2D isn't triggered always so there must be something wrong.
    Already tested setting the rigidbodies of the target and projectile which is shooted onto the target to Collision Detection = continous and Interpolate but didn't help...
    Is this intended or a Bug?
     
    Last edited: Feb 25, 2016
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,456
    sqrMagnitude is a function of Vector2 so no, it's not changed or broken. relativeVelocity might have changed though, but you'd need to check.

    @MelvMay would probably offer more info if he's around.
     
    grosssmutttr likes this.
  3. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    167
    Perhaps the relativeVelocity also hasn't changed but I can remember that there was an issue with the collision detection before. So perhaps this issue is back again?
     
  4. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    167
    Submitted a report: (Case 774128)
     
  5. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    167
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,488
    There was a bug reported regarding relativeVelocity not always reporting correctly (for some reason) so it would seem like this is the problem you're experiencing.

    This is one of the bugs scheduled to be looked at next week.
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,488
    It would be really useful if you could create a stripped-down reproduction of the problem rather than a huge project. It makes finding the issue much easier otherwise it can be very difficult it debug the issue with so much going on.
     
  8. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    167
    @MelvMay Thanks for your reply.
    Have you already tried the submitted project or should I create a stripped down version?
     
unityunity