playMaker

Author Topic: How Raycast work?[SOLVED]  (Read 22497 times)

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
How Raycast work?[SOLVED]
« on: September 19, 2011, 05:47:32 PM »
Hi all
I am trying make a small game
When bullet collide with any collider make a texture hole.
How Raycast work?
Please any help
Bye
« Last Edit: January 31, 2012, 04:20:12 PM by Sebastiao »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: How Raycast work?
« Reply #1 on: September 20, 2011, 02:52:00 PM »
If you're using the mouse cursor to shoot bullets look into MousePick.

Take a look at the MainCamera FSM in PlaymakerSamples/TestLab/Input/MouseClickToPlace or MouseClickToDrag samples to see how to use MousePick.

Also take a look at the TargetManager in the PlaymakerSamples/TestLab/Physics/AddForceToMouseOverObject sample.

Raycast requires an origin, and direction, so is well suited for AIs that need to shoot rays into the world. MousePick is easier if it's the player shooting from the camera's position.


Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How Raycast work?
« Reply #2 on: September 20, 2011, 03:21:07 PM »
Thank you Alex ;D
I will see better
Bye

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How Raycast work?
« Reply #3 on: September 25, 2011, 02:23:28 PM »
Can some guy give me a int how can I make a bullet hole in wall?
Bye
 

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How Raycast work?
« Reply #4 on: September 26, 2011, 05:44:11 PM »
Please :'(

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: How Raycast work?
« Reply #5 on: September 26, 2011, 08:03:23 PM »
You can store the position and normal generated by the raycast or collision and use those with Create Object to make a bullet hole object in the right place. Use the hit normal to rotate the created object.

There are also dedicated decal systems that might work better for bullet holes... You could do a search on the unity forums, and maybe combine such a system with playmaker...

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How Raycast work?
« Reply #6 on: September 27, 2011, 12:54:47 PM »
Humm seems  good I will see thanks Alex ;D
Bye

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How Raycast work?
« Reply #7 on: September 27, 2011, 05:32:48 PM »
Can you explain a little better?
Bye
Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How Raycast work?
« Reply #8 on: December 07, 2011, 05:01:35 AM »
Hi,

 OK, let's do this raycast thing all the way :)

What we will achieve now? A proper use of raycast hit info so that we can place a gameObject at the hit position and oriented properly.

What you need:

I have created a simpler version of raycast available here. you will need it for this example, or else you can use rayCast, that will work just fine too ( only more "difficult" to set up)

http://hutonggames.com/playmakerforum/index.php?topic=900.0



The scene:

1: create one gameObject acting as the rayCast fire source ( called "laser" )
2: create a sphere acting as the object being hit ( called "target")
3: WARNING: orient the "laser" z axis to point to the "target"
4: create a cube ( called ("hit result")  that we will position and orient based on the "laser" hit on the "target"
WARNING: The "hit result" game Object must not be hit by the raycast!!! so select the cube and set is layer to "ignore raycast"

The playmaker fsm

1: select the "laser" and add a fsm to it
2: create three fsm Vector 3 variable: "hit point", "hit normal", and "look at target"
3: in the start state, add a "Raycast from gameObject" action
  -- set its Repeat interval to 0 ( we only want to fire once), if you want to fire multiple times, simply call that state again)
4: add a "Get RayCast Hit info" action
   -- store the Hit point in the fsm variable "hit point"
   -- store the Normal in the fsm variable "hit normal"
5: add a "set position" action
  -- specify the GameObject and point to "hit result"
  -- set the Vector to "Hit plane"
6: add a "vector3 Operator" action
  -- set Vector 1 to "hit point"
  -- set Vector 2 to "hit normal"
  -- Store the result in  the fsm variable "Look at target"
7: add a "look At" action
  -- Specify the game Object and point to "hit result"
  -- set the target position to "Look at target"
  -- uncheck "Keep vertical"

And done. Run and you will see the "hit result" being positionned at the hit position and oriented properly based on the hit normal.


I can see that for beginners this might be too much for a "simple task", maybe the raycast action should actually provide directly the hit position and normal or even actually accept a gameObject that would be positionned and oriented for you. The other pitfall is to want the raycast to work "every frame", that requires some set up to do so as well). if I have time int he next few days, I'll do such action.
 

 Bye,

 Jean

 

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How Raycast work?
« Reply #9 on: December 07, 2011, 01:44:18 PM »
I have made this
And can´t shot maybe they should are in different states?
Bye thanks

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How Raycast work?
« Reply #10 on: December 08, 2011, 07:27:23 PM »
Please help me :-[
Bye

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How Raycast work?
« Reply #11 on: December 09, 2011, 12:18:31 AM »
Hi,

 Not available most of today, will see if I have time to give you more advice before the week end.


 Bye,

 Jean

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: How Raycast work?
« Reply #12 on: December 09, 2011, 01:12:35 AM »
Hi. I followed these instructions and got it to work. When I did, I assumed "Hit Plane" was a mistake, and he meant "Hit Normal". Since they sound like the same thing. Where you have "Hit Plane" as the Vector in your Set Position action, you actually want the "Hit Point".

So you raycast, store what the ray hits and the normal of what it hits. You want to set the position of what it hits. That part is easy since it's the exact "Hit Point". The rotation of what it hits is why there's a Look At action. The rest looks right.

I'm including a picture of what I did. Note, the raycast action is in the first State, which you can't see. It's set to Repeat Interval 0 so it only casts a ray once, if it hits something it sends the Finish Event which triggers the next bit you can see here. Should still work with your Raycast being in the same State.
« Last Edit: March 30, 2013, 05:37:41 AM by FractalCore »

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How Raycast work?
« Reply #13 on: December 09, 2011, 08:38:31 AM »
Thanks Jean
Thanks FractalCore
I´m gonna try it
Bye

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How Raycast work?
« Reply #14 on: December 09, 2011, 09:04:59 AM »
I think the problem is the Look At Action
Your Look At Action is different than my
Where did you get it?
I have this now

Bye thanks for any help