Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
Johnideev

Raycast Destroy(hit.collider.gameObject);

Question

Hi,this is my first topic here :d Anyway can you guys please help me at raycasts,its my first time working with them,so i just need script (Request) i want my player destroys when he touches raycast,like:

Please login or register to see this code.

Can someone please help me,dont know anythng about this.Please someone help me...Ill be very thankful.

Share this post


Link to post
Share on other sites

17 answers to this question

Recommended Posts


  • 0
Please login or register to see this quote.

Hi, this script should work :)

Please login or register to see this code.

your mistake was at "Hit.collider.gameobject.tag", it should be "Hit.collider.tag" :)

Share this post


Link to post
Share on other sites
  • 0

In my opinion documentation explains everything:

Please login or register to see this link.

Just try to write script by yourself and i'm sure you will understand how works raycast.

If tomorrow you will bump this topic i will help you.

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Ohhh.....this script:

Please login or register to see this code.

Works perfect,i understand this script,but i dont know how to modify it,where to put Destroy player command and make it work...Thats only problem. (just need to destroy player with tag: Player) :)

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Thank you OneManArmy for that now i understand something :d Anyway you see this line:

Please login or register to see this code.

i have light like flashlight,like laser...well

that line of code detects everything what is on its way like walls,obstacles,objects,everything.....I want that script line only detects player (ME),how can i do that? How can i remake the script that its only detects me not everything from world....Please help me :)

Share this post


Link to post
Share on other sites
  • 0

pay attention on Layers (layerMask). Your player must have own layer and in raycast you can add to detect only selected layer (player layer).

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Okey its worked,but realy buggy for me (sometimes it just not destroyed player),so i like the other way it is possible only with your help...I tested out this script:

Please login or register to see this code.

It detects EVERYTHING what is in raycast way,and always prints out: "There is something in front of the object!" because it detects everything,every object,every obstacle....well is it possible that it only detects player when he walks in raycast way,not all world objects,but player only.... How to make this detects only player:

Please login or register to see this code.

Please help me :)

Share this post


Link to post
Share on other sites
  • 0

I already wrote you in my last post.

You should READ documentation. If it's hard for you, then PLAY games, not make them.

Raycast (origin : Vector3, direction : Vector3, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers)

origin The starting point of the ray in world coordinates.

direction The direction of the ray.

distance The length of the ray

layerMask A Layer mask that is used to selectively ignore colliders when casting a ray.

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Do this:

If you want the Raycast for not to hit [ignore Objects except Player],

set the objects layer to Ignore Raycast. [see attachment] :)

Share this post


Link to post
Share on other sites
  • 0

this way you will need to set all gameobject to "IgnoreRaycast" (even ground), and that's totally wrong. You need to create new layer (lats call it "Player") and in raycast script you should tell to detect only this "Player" Layer.

You can find example in FPS Kit.

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Thats what i need ^:)^^'> Can you please show me how? (Yeah i know i must do it myself,but im wasting time with this :!! in this problem i dont know how to get out) And i cant find this script in fps kit.

Share this post


Link to post
Share on other sites
  • 0

I'm also wasting my time, when i try to help someone who don't want learn (who wants only ready script, or step by step tutorial). You will use raycast in future a lot, so you can spend your time on that.

Most important is to understand how to use documentation.

Ok, this time i will show you... Wait 20 minutes.

Share this post


Link to post
Share on other sites
  • 0

[youtubehd]Please login or register to see this link. [/youtubehd]

Download Example Project:

[attachment=0]Raycast.rar[/attachment]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...