Search Unity

Survival Shooter Demo Project

Discussion in 'PSM' started by jordiboni, Jan 25, 2015.

  1. jordiboni

    jordiboni

    Joined:
    Aug 14, 2013
    Posts:
    26
    Hello, I am trying to import survival shooter demo project used in Unite 2014 but I don't know why with this Unity build physics doesn't work with this call:

    Code (CSharp):
    1. // Perform the raycast against gameobjects on the shootable layer and if it hits something...
    2. if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
    3. {
    4.     // Try and find an EnemyHealth script on the gameobject hit.
    5.     EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
    6.  
    7.     // If the EnemyHealth component exist...
    8.     if(enemyHealth != null)
    9.     {
    10.         // ... the enemy should take damage.
    11.         enemyHealth.TakeDamage (damagePerShot, shootHit.point);
    12.     }
    13.  
    14.     // Set the second position of the line renderer to the point the raycast hit.
    15.     gunLine.SetPosition (1, shootHit.point);
    16. }
    I defined correctly shootable layer in all prefabs.
     
  2. Stiffx

    Stiffx

    Joined:
    Oct 27, 2014
    Posts:
    455
    Are you sure this script <EnemyHealth> is applied to the gameobect hit by raycast?
     
  3. jordiboni

    jordiboni

    Joined:
    Aug 14, 2013
    Posts:
    26
    Yes, I checked that all gameobjects are correctly configured.

    enemy.png

    player.jpg
     
  4. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    IIRC (but I might be mistaken) the Survival Shooter uses some Unity 4.5/4.6 features.
    And if that's the case the project needs to be altered to work with Unity 4.3.

    Does the project work as expected in the editor?
     
  5. jordiboni

    jordiboni

    Joined:
    Aug 14, 2013
    Posts:
    26
    This project works with Unity 4.6 UI but I removed all the UI elements. If I play the project in Editor Mode doesn't works Physics.Raycast. I tried other Unity version and Physics.Raycast works fine
     
  6. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Yeah, so then it sounds like something in the project is broken the when running in Unity 4.3 (regardless of PSM).
     
  7. jordiboni

    jordiboni

    Joined:
    Aug 14, 2013
    Posts:
    26
    Ok, I will check Physics.raycast in a new project. Thx!
     
  8. jordiboni

    jordiboni

    Joined:
    Aug 14, 2013
    Posts:
    26
    If you set this script to the main camera and create a quad in front of the camera, with layer Default, console shows the print message. If you set the quad with the layer 9, console don't shows the message! (Note: console only shows the message if the quad uses layer Default. If I set layer to 1 or 2, console doesn't shows the message)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ExampleClass : MonoBehaviour {
    5.     void Update() {
    6.         Vector3 fwd = transform.TransformDirection(Vector3.forward);
    7.         if (Physics.Raycast(transform.position, fwd, 10,9))
    8.             print("There is something in front of the object!");
    9.      
    10.     }
    11. }
    12.  
    I created a new project without any other script or model
     
  9. jordiboni

    jordiboni

    Joined:
    Aug 14, 2013
    Posts:
    26
    I modified my script and now my source code is

    Code (CSharp):
    1. RaycastHit hit;
    2. if (Physics.Raycast(transform.position, fwd, out hit,100, layer))
    3. {
    4.     float distanceToGround = hit.distance;
    5.  
    6.  
    7.     print ("distanceToGround " + distanceToGround + " layer " + hit.transform.gameObject.layer + " name " + hit.transform.gameObject.name);
    8.  
    9.     Debug.DrawLine(transform.position, hit.point);
    10. }
    It doesn't works fine.


    if I change my source to

    Code (CSharp):
    1. RaycastHit hit;
    2. if (Physics.Raycast(transform.position, fwd, out hit))
    3. {
    4.     float distanceToGround = hit.distance;
    5.  
    6.     print ("distanceToGround " + distanceToGround + " layer " + hit.transform.gameObject.layer + " name " + hit.transform.gameObject.name);
    7.  
    8.     Debug.DrawLine(transform.position, hit.point);
    9. }
    10.  
    It shows correctly the layer number
     
    Last edited: Jan 26, 2015