Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Franck on September 21, 2018, 10:39:54 AM

Title: Problem with raycast normal
Post by: Franck on September 21, 2018, 10:39:54 AM
Hello everyone,

I'm trying to create a bullet hole with a raycast hit.

I have a state in which the "raycast" action that creates the raycast and stores the informations.

In the following state I have a "create object" action that contains my "bullet hole" object and gets the position of hit raycast ("hit point") and rotation ("hit normal").

But when I pull the raycast my bullet holes are positioned correctly on vertical walls but not on floors.

The bullet holes still remains positioned vertically.

Have I forgotten something?
Title: Re: Problem with raycast normal
Post by: djaydino on September 22, 2018, 03:18:03 AM
Hi.
What action do you use to set the rotation?

I think you can try using "Quaternion Look Rotation"

By the way you should also look into 'pooling' then instead of creating.
Title: Re: Problem with raycast normal
Post by: Franck on September 22, 2018, 03:56:39 AM
Hi djaydino,

I do not use any action to set the rotation, just create object and in it I set my "hit normal" info in "rotation" field.
I can not see any "pooling" action in PM. What do you mean?
Title: Re: Problem with raycast normal
Post by: djaydino on September 22, 2018, 04:35:49 AM
Hi.
Did you try using "Quaternion Look Rotation" instead of the rotation field?

Pooling is a solution to use instead of creating and destroying (which is expensive cpu wise See this link (https://www.youtube.com/watch?v=7UswSdevSpw) for an explanation why you should use pooling.)
Pooling will create a preset amount of the object (disabled) and reuse them when needed

There are several pool asset on the asset store, but there is also a simple one on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181) called 'Pooler'
Also in one of the next PlayMaker updates there will be a build in pool system included.
Title: Re: Problem with raycast normal
Post by: Franck on September 22, 2018, 05:13:11 AM
What you is to put a quaternion look rotation action before the create object action?
And in the direction I set the hit normal info then store the result. And after, in the create object action I set the result of quaternion look rotation in the rotation field of create object?
Title: Re: Problem with raycast normal
Post by: Franck on September 22, 2018, 05:42:46 AM
Ok, so I downloaded the Pooler in the ecosystem. I put the action "Quaternion Look Rotation" before the Pooler, in direction I put the "Hit Normal" of my raycast and I store the result (hitNormal, as quaternion).

Then I put a "Pooler Pool" in which I have my Bullet Hole prefab. Then a Spawn Pooler, in Position I have my Raycast hit point, but in rotation I do not really know what to put.
I tried with the Hit Normal of the raycast but it does not work.
So the Quaternion Look Rotation is useless here.
Title: Re: Problem with raycast normal
Post by: djaydino on September 22, 2018, 09:59:53 AM
Hi.
After you pool the object you should store the object and then use the "Quaternion Look Rotation" with the stored object.

I looked to a c# tutorial doing this :



So he is doing a raycast,
Then instantiate (where he should pool)

Then uses the hit point + hit normal multiplied by 0.00001 (this is to set it a little bit in front of the hit position, so you wont get flickering images)
and Quaternion.LookRotation with the hit normal.

I  will see if i can make a sample after the weekend.
Title: Re: Problem with raycast normal
Post by: Franck on September 22, 2018, 01:08:26 PM
thank you djaydino you are great  :)
Title: Re: Problem with raycast normal
Post by: djaydino on September 23, 2018, 07:01:48 AM
Hi.
Did you get it to work?
Title: Re: Problem with raycast normal
Post by: Franck on September 24, 2018, 03:44:20 AM
Hi djaydino,

nop it doesn't work :(
I can't take the stored object in the Quaternion Look Rotation.

(https://imageshack.com/a/img924/3407/1HJRKk.jpg)
Title: Re: Problem with raycast normal
Post by: djaydino on September 24, 2018, 08:42:06 AM
Hi.
I tried a setup and i got it to work,
I will try to make a video tomorrow.
Title: Re: Problem with raycast normal
Post by: Franck on September 24, 2018, 09:18:16 AM
ohhh cool!
can't wait lol
Title: Re: Problem with raycast normal
Post by: Franck on September 26, 2018, 02:23:31 AM
Hi djaydino,

did you make the video? I'm so stuck :(
Title: Re: Problem with raycast normal
Post by: djaydino on September 26, 2018, 05:35:24 AM
Hi.
Sorry i had to record in bits and pieces due a lot of construction work going on here.

I am editing at the moment and will try to finish it today :)
Title: Re: Problem with raycast normal
Post by: Franck on September 26, 2018, 06:09:59 AM
You do not have to say sorry lol.

Really a big thank you for helping us here and I know that sometimes we are annoying :)

But thanks again to you :)
Title: Re: Problem with raycast normal
Post by: djaydino on September 26, 2018, 09:45:10 AM
Hi.
It's not one of my best video's but it explains how to do :)

Title: Re: Problem with raycast normal
Post by: Franck on September 27, 2018, 01:52:37 AM
wow thanks djaydino it works.

You win a subscriber to your youtube channel!

I use with that the "create object" action because with pooler it is so complicated for my shotgun. Indeed I have 12 raycasts in my FSM to spawn 12 bullet holes and with Pooler I will have too many states...lol

However, Is there a way to decal the object (bullet hole) a bit because it clip when it spawn on the objects?
Title: Re: Problem with raycast normal
Post by: djaydino on September 27, 2018, 02:59:59 AM
Hi.
Aw i forget to show the bullet hole prefab on the video....

I have an empty object and in there i have a plane (child) with the bullet hole and i have the (i believe) z position set to 0.0001 and x rotation to 90
Title: Re: Problem with raycast normal
Post by: Franck on September 27, 2018, 03:32:45 AM
Oh yep, got it !
Thanks a lot djaydino :)
Title: Re: Problem with raycast normal
Post by: djaydino on September 27, 2018, 07:36:25 AM
Hi.
You can also use an offset if needed, just add these 2 actions on the top of the 'Spawn Bullet Hole' state :

(https://i.imgur.com/flhsQREl.png)
Title: Re: Problem with raycast normal
Post by: djaydino on September 28, 2018, 09:47:46 PM
Hi.
Uploaded video link with a new one (including offset info)

Title: Re: Problem with raycast normal
Post by: Franck on September 29, 2018, 07:41:27 AM
Yep I saw, I subscribed to your channel :)