browser icon
You are using an insecure version of your web browser. Please update your browser!
Using an outdated browser makes your computer unsafe. For a safer, faster, more enjoyable user experience, please update your browser today or try a newer browser.

Raycast Hit!

Posted by on July 9, 2012

Hello guys! Programmer here! :D

So, after we found out that there are some problems regarding our old selecting method (yes selecting the object, what else?), we decided to research more about other possibilities regarding selection method, as this is indeed one of the most important thing in hidden-object game.

So, I decided to try out the Raycast Hit, which Mr. Alvin have tried it before and said that he got some problems regarding Raycast hit, but at that time I didn’t have the chance to really go into raycast hit, so here it is some snippet of the raycast hit:

function Update () {
   if (Input.GetMouseButton(0)) {
      var hit : RaycastHit;
      var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

      if (Physics.Raycast(ray, hit, 100.0)) {
         if(hit.transform.gameObject.tag == "Cube") //do something with cube objects
         else if(hit.transform.gameObject.tag == "wrong!") // is not our target.
         // so on so forth

So far the code is working like a charm in test scene, will update you guys when we actually move this inside the game scene. Hope this helps the others. =)

Keep Coding!



2 Responses to Raycast Hit!

  1. Alvin

    Remember that the ‘ray’ might allow players to reach the target although it is hidden behind another object. Try it out and look into it more closely.

  2. Alvin

    To detect whether players have swiped (rotate camera) and therefore not producing any ray, try using the mousebuttondown and mousebuttonup conditions. Implement it by checking if the object hit during mousebuttondown is the same as the object hit during mousebuttonup. This might help.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>