Forum rules - please read before posting.

Raycast issues\questions

Hello,

this isn't a bug or anything but probably something wrong on my side. I've made a quick video for Chris to show what I'm attempting.

Basically, I want a door to open when I click on it, and I got a pre-made script that helps me in this - I'd guess posting little parts of it would be fine if it's really needed. What happens though, is that when at the beginning of the video I click with the cursor, the door doesn't open, and the reason seems to be because it doesn't consider the click as coming from the "real cursor". (btw, when I clicked, the standard cursor disappeared merely because that's the Unity editor). Later in the video you can see the door open and close even if my cursor isn't on it, and that's because the "fake cursor" is actually placed on it. 
How can I fix this?

Comments

  • edited November 2014
    You'd have to modify the script, as it seems to be looking for the hardware cursor position, and not AC's one.  This should return the correct vector:
    GameObject.FindWithTag (Tags.gameEngine).GetComponent ().GetMousePosition ();
  • edited November 2014
    Hm. Couldn't get it to work for some reason.
    The only line that made sense switching was:
    Ray ray1 = Camera.main.ScreenPointToRay(Input.mousePosition);

    so what I tried is:

    Ray ray1 = Camera.main.ScreenPointToRay(GameObject.FindWithTag (Tags.gameEngine).GetComponent<PlayerInput>().GetMousePosition());

    but I've got 3 nice critical errors.

    Doorscript.cs(100,48) error CS0246: The type or namespace name `PlayerInput' could not be found. Are you missing a using directive or an assembly reference?
    Doorscript.cs(100,48) error CS1502: The best overloaded method match for `UnityEngine.Camera.ScreenPointToRay(UnityEngine.Vector3)' has some invalid arguments
    Doorscript.cs(100,48): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.Vector3'

    I've noticed that <PlayerInput>().GetMousePosition turns into red... not sure why since the script is indeed in GameEngine ?
  • Sorry, forgot the namespace.  Try AC.PlayerInput instead.
  • Worked like a charm. Yet again, thanks.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.