playMaker

Author Topic: Problem with normals + raycast + create object [SOLVED]  (Read 4880 times)

TheDMan

  • Playmaker Newbie
  • *
  • Posts: 4
Problem with normals + raycast + create object [SOLVED]
« on: March 04, 2014, 01:03:09 AM »
I've searched the forum and found a few similar topics and tried various things mentioned in them, but they didnt help with my problem.

Here are the steps of the process I'm doing:

1. So, I'm firing a raycast from the main camera of the FPS controller (which i've made fire a ray with a click of the mouse button).

2. I store the "Hit Point" in a vector3 variable called "hitPosition" and I store the "Hit Normal" in a vector3 variable called "hitNormal".

3. In the next state, I have a "Create Object" action, with the Game Object being a simple mesh a single quad/plane, the "Position" is set to the stored "hitPosition" vector3 var.

4. and I set the Rotation to the stored "hitNormal" vector3 var.

When I click play, the quad/plane gets created in the correct position of the ray hit, but no matter what I try to get it to take into account the normal, it ignores it.

The quad/plane all gets created and placed in the right position but they all are facing the exact same way no matter what I try (see attached image).

I've tried "Look at" (which throws an endless "Look rotation viewing vector is zero" error).



Am I missing something?  How should I approach making the quad/plane get created/pasted with the normal being taken into account like a decal?
« Last Edit: March 17, 2014, 11:37:19 PM by TheDMan »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Problem with normals + raycast + create object
« Reply #1 on: March 04, 2014, 06:28:01 AM »
Hi,

 you want the red quads to act as billboard? always looking at the camera or are you trying to make decals on walls?

bye,

 Jean

TheDMan

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Problem with normals + raycast + create object
« Reply #2 on: March 04, 2014, 01:16:53 PM »
Hi,

 you want the red quads to act as billboard? always looking at the camera or are you trying to make decals on walls?

bye,

 Jean


Definitely trying to make it decals.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Problem with normals + raycast + create object
« Reply #3 on: March 05, 2014, 02:49:27 AM »
Hi,

 you need to debug this step by step.

forget the room, have just one plane at an angle ( just to make sure the normal is all weird), fire one raycast, get it's normal and position a object using that hit position and normal.


I have linked a raycast scene where I use the normal to position an object. See how this is done and take it from there.

https://dl.dropboxusercontent.com/u/17356625/Unity/playmaker/samples/Raycast%202.unitypackage


bye,

 Jean

TheDMan

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Problem with normals + raycast + create object
« Reply #4 on: March 06, 2014, 12:28:33 AM »
The scene you made works fine and great.

If I literally duplicate the exact same raycasting settings/variables/and state actions I get this repeating error.


"Look rotation viewing vector is zero
UnityEngine.Quaternion:LookRotation(Vector3)
LookAtActionEditor:OnSceneGUI() (at Assets/PlayMaker/Actions/Editor/LookAtActionEditor.cs: 27)"


The error only exists with the "Look At" action active. When I disable it, then the error disappears.  More specifically, when the Target Position is set to "look at target".

« Last Edit: March 06, 2014, 12:31:11 AM by TheDMan »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Problem with normals + raycast + create object
« Reply #5 on: March 06, 2014, 07:27:40 AM »
Hi,

 This is happening because your lookat position is the same position as the starting point of the ray and therefore there is an infinite amount of possibilities and lookat doesn't like that... ( it divides by 0 basically).

 so the problem is in the definition of your look at position OR the position of the stating point of the raycast.

bye,

Jean

TheDMan

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Problem with normals + raycast + create object
« Reply #6 on: March 17, 2014, 11:36:58 PM »
After trying various things I was able to work it out.

The main thing that helped was splitting various aspects of the actions into separate states. So I have the Raycast in one state,  the Set Position in another state, and the Vector3 and Look At in other state.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Problem with normals + raycast + create object [SOLVED]
« Reply #7 on: March 18, 2014, 08:57:01 AM »
Hi,

 Good. I am glad its' sorted. I do experience this in some occassions as well, I can't really explain it, not sure if it's playmaker related or actually something within Unity or the c# compiler, that we don't understand. I know for sure that when working with some assets, you have to wait one frame for example, so when splitting into different states doesn't work, try inserting a "next frame event" as well.

bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Problem with normals + raycast + create object [SOLVED]
« Reply #8 on: March 18, 2014, 08:58:28 AM »
Hi,

 d'oh, actually I know what it is: it's because one action use fixedUpdate and others use update, and so depending on the order, an action doesn't get the right value because it has not been set at the same time, and actuall later in the lifetime of a frame ( lateupdate for example). Maybe splitting into states correct this situation.

bye,

 Jean