Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Dev_Sebas on September 19, 2011, 05:47:32 PM

Title: How Raycast work?[SOLVED]
Post by: Dev_Sebas 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
Title: Re: How Raycast work?
Post by: Alex Chouls 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.

Title: Re: How Raycast work?
Post by: Dev_Sebas on September 20, 2011, 03:21:07 PM
Thank you Alex ;D
I will see better
Bye
Title: Re: How Raycast work?
Post by: Dev_Sebas 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
 
Title: Re: How Raycast work?
Post by: Dev_Sebas on September 26, 2011, 05:44:11 PM
Please :'(
Title: Re: How Raycast work?
Post by: Alex Chouls 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...
Title: Re: How Raycast work?
Post by: Dev_Sebas on September 27, 2011, 12:54:47 PM
Humm seems  good I will see thanks Alex ;D
Bye
Title: Re: How Raycast work?
Post by: Dev_Sebas on September 27, 2011, 05:32:48 PM
Can you explain a little better?
Bye
Thanks
Title: Re: How Raycast work?
Post by: jeanfabre 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 (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

 
Title: Re: How Raycast work?
Post by: Dev_Sebas 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
Title: Re: How Raycast work?
Post by: Dev_Sebas on December 08, 2011, 07:27:23 PM
Please help me :-[
Bye
Title: Re: How Raycast work?
Post by: jeanfabre 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
Title: Re: How Raycast work?
Post by: FractalCore 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.
Title: Re: How Raycast work?
Post by: Dev_Sebas on December 09, 2011, 08:38:31 AM
Thanks Jean
Thanks FractalCore
I´m gonna try it
Bye
Title: Re: How Raycast work?
Post by: Dev_Sebas 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
Title: Re: How Raycast work?
Post by: FractalCore on December 09, 2011, 08:03:59 PM
Not sure why your Look At is missing a Every Frame option. You might be using the Playmaker version before 1.2.1. And it is good to have, I tried turning it off and there was a slight lag in aligning the object to the hit normal. But it did still work.

I suggest turning on the Debug option in the Raycast and the Look At. Then if you drag the Game view to be there at the same time as the Scene view, like in this picture... When you hit play you'll be able to make sure the ray is firing the right way and you can also see the normal (grey line) that the box is aligning to. You can also move the "Lazer" and see it update in realtime.
Title: Re: How Raycast work?
Post by: Dev_Sebas on December 10, 2011, 11:58:10 AM
I have the last version of Playmaker and I don´t have this action
Title: Re: How Raycast work?
Post by: Dev_Sebas on December 10, 2011, 01:32:28 PM
It´s working but bad
I will post a video
Title: Re: How Raycast work?
Post by: Dev_Sebas on December 10, 2011, 02:15:19 PM
There is it
http://www.youtube.com/watch?v=aFPPOGvWmZA&list=UUcnMqLJyPsRSuAleeojEBdw&feature=plcp (http://www.youtube.com/watch?v=aFPPOGvWmZA&list=UUcnMqLJyPsRSuAleeojEBdw&feature=plcp)
Please help me
Bye
Thanks for any help
Title: Re: How Raycast work?
Post by: FractalCore on December 10, 2011, 09:26:38 PM
Your Set Position Action is using the Hit Normal instead of the Hit Point. That might explain why the cube appears at the base of the raycast instead of where the ray hits something.

Eventually you'll want to replace that with a Create Object, set to create the hit result cube prefab you have. That's assuming you want to use this as a system for spawning a particle system and leaving a bullet hole or something.

But there appears to be other things that might be going wrong. You seem to have a ray that points to what could be world 0,0,0. That shouldn't happen.

And I'm not sure about the "Target" sphere, is it to visualize something? I didn't see anything using it in your FSM.
Title: Re: How Raycast work?
Post by: Dev_Sebas on December 11, 2011, 06:53:38 PM
"Target" sphere? Jean said only for we create it.
I have put my cube on prefab and added create object too but it´s the same
Bye
Thanks for any help
Title: Re: How Raycast work?
Post by: jeanfabre on December 14, 2011, 07:21:32 AM
Hi

Ok, I created a package showing the implementation so that you can study a working example and find out what could be wrong in your implementation.

 The post is here:
http://hutonggames.com/playmakerforum/index.php?topic=900.msg3781#msg3781 (http://hutonggames.com/playmakerforum/index.php?topic=900.msg3781#msg3781)

and the package actually available here:
http://dl.dropbox.com/u/17356625/Unity/projects/misc/raycast.unitypackage (http://dl.dropbox.com/u/17356625/Unity/projects/misc/raycast.unitypackage)

Bye,

Jean
Title: Re: How Raycast work?
Post by: Dev_Sebas on December 14, 2011, 08:54:04 AM
Thanks Jean I will try
Bye