Search Unity

Question Problem with collision detection

Discussion in 'Physics' started by garet_ia, May 23, 2020.

  1. garet_ia

    garet_ia

    Joined:
    Mar 29, 2020
    Posts:
    3
    Hi,

    I am new to Unity and trying to develop a simple game. In my situation a spaceship is moving through space and shoots at stuff (asteroids and enemies) coming at it.
    Everything was working fine until I tried running the game on older laptop with built-in videocard. The projectiles of the ship almost never hit smaller objects, they just go through and collision dosent get detected.
    Ive tried changing timestep form project settings to a lower value, tried all the collision options that the rigidbody component offers. Tried also spliting the projectile (a lazer bolt) to several smaller parts that travel together with no success.
    The PC everything works fine is AMD 3600 CPU and Radeon 570 videocard, on the laptop that the games runs like 10 times slower is kinda old(7-8 years) with built-in video. I also have another PC with 4 core processor and 760 nvidia videocard - on this PC the miss happanes like 1 miss per 5-6 shots.
    How can I fix this issue? My game is quite simple, not many things going on at once and I dont understand why this is happaning.
     
  2. leftshoe18

    leftshoe18

    Joined:
    Jul 29, 2017
    Posts:
    61
    Are the projectiles moving in FixedUpdate() or Update()?
     
  3. garet_ia

    garet_ia

    Joined:
    Mar 29, 2020
    Posts:
    3
    First I was using Update(), after some reading about this problem I changed to FixedUpdate with no difference, projectiles keep going through targets without any collision beeing detected on the low-specced PC.
    What I understand about this issue - it is that my projectiles and targets are small and fast moving (projectiles) and when frame rate is slow, the actuall collision happens between frames and thats why it is not detected. Thats why this is not a problem for a better PC, there are more frames per second and greater chane for a collision to happen.
     
  4. leftshoe18

    leftshoe18

    Joined:
    Jul 29, 2017
    Posts:
    61
    Try setting the rigidbody collision to Continuous Dynamic and see if that helps.
     
    garet_ia likes this.
  5. garet_ia

    garet_ia

    Joined:
    Mar 29, 2020
    Posts:
    3
    Your post made look the code for 100th time and i found an update that I have missed, changed it to fixed, it definatelly imporved, but there were misses still, after that I changed the timestep from 0.02 to 0.01 and it suddenly works :) Thanks for the help :)
     
    leftshoe18 likes this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    I just wanted to add that the frame-rate will make no difference if the simulation is running during fixed-update. The simulation might get run several times to catch-up to game time but that's it. What you're describing though is called collision tunneling and it's nothing to do with frame-rate but how discrete collision detection works where it basically checks to see if it's colliding where it moves to. With discrete, fast moving colliders can "step over" smaller colliders. Continuous collision detection sweeps from its old position to the new position and detects contacts in-between so stops tunelling but it costs more to calculate.

    Anyway, hope that helps.