Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Posts
    10

    Practical Game Development in Unity 4 - Missile Silos Part 2 - Wall Click Issue

    I followed along the whole video and the missiles weren't firing from the silo. I double checked all the code and everything was exactly as the video.

    I added some debug lines to PlayerManager.cs to get a count of the targets. It was never making it past the "if (targets.Count == 0" line. The count was always 0 and it was just returning there.

    After hours of quadruple checking, I rotated the wall the opposite direction -90 degrees (originally, it was 90 degrees). SOB it worked! I was about 3 seconds away from drop kicking my computer...

    I'm not sure why the other side of the plane wasn't registering the click, but I wanted to share in case anyone else has this problem.

    Code:
        public void Update()
        {
            if (!Input.GetMouseButtonDown(0))
                return;
    
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            var targets =
                (from cast in Physics.RaycastAll(ray)
                 where cast.collider == Wall
                 select cast).ToList();
    
            Debug.Log("Count 1 = " + targets.Count);
    
            if (targets.Count == 0)
                return;
    
            Debug.Log("Count 2 = " + targets.Count);
    
            var target = targets[0];
            var silo = GetClosestSilo(target.point);
    
            if (silo == null)
                return;
    
            silo.ShootAt(target.point);
        }

  2. #2
    Join Date
    Jan 2012
    Posts
    1
    i actually did rotate it and it didnt work either

    then i deleted it and made a new one,, and have not rotated it since..
    googled , found u , rotated it, and it freaking worked, unity is crazy sometimes

    i also had other issues with the wall, altho i unchecked the "trigger" on the wall collider, missiles would still get destroyed instantly after respawn, because apparently they hit the wall collider .. googled, and it was a known unity bug..

    that also got fixed on its own! :@
    its really had to learn something brand new, and face such bugs

  3. #3
    Join Date
    Sep 2013
    Posts
    1
    Hey,

    I'm having a different problem with the wall click business, but I noticed that rotating the wall is necessary for some stupid reason.

    My problem: for some reason my missiles are veering down and to the side; clicks are registering, but the direction is off.

    I re-instantiated most of my objects (including the wall) and triple checked the code (see below). I am beside of myself in frustration, in part because i'm trying to make a mouse targeting game (though I'm using very different coding methods)

    public class PlayerManager : MonoBehaviour
    {
    public Collider Wall;


    public void Update()
    {
    if (!Input.GetMouseButtonDown(0))
    return;

    var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

    var targets =
    (from cast in Physics.RaycastAll(ray)
    where cast.collider == Wall
    select cast).ToList();
    if (targets.Count == 0)
    return;

    var target = targets[0];
    var silo = GetClosestSilo(target.point);

    if (silo == null)
    return;

    silo.ShootAt(target.point);
    }
    private Silo GetClosestSilo(Vector3 point)
    {
    var possible =
    // go refers to "game object"

    // for ease of access cast it to a silo
    // filter
    from go in FindObjectsOfType(typeof(Silo))
    // loops through every object of type silo
    let Silo = (Silo) go
    // for ease of access cast it to a sil
    where Silo.CanFire
    // filter out silos that cannot fire
    let distance = (Silo.transform.position - point).sqrMagnitude
    // find the distance^2 between each silo and the selected point
    orderby distance
    select Silo;

    return possible.FirstOrDefault();
    }

    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •