Howdy, Stranger!

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

How to get direction from cursor

TheLoafDudeTheLoafDude Member
edited June 2020 in Programming

I have this 3D game I'm developing

In this game I am a roll of toilet paper

If I press space, I get yeeted towards the cursor

I started using raycasts to do this, but that didn't work out, AT ALL

So, how do I get the toilet paper to jump towards the cursor? (how do I get the direction for where the cursor is)

Best Answers

  • TheLoafDudeTheLoafDude Member
    edited June 2020 Accepted Answer

  • Accepted Answer

    No, you actually have to use raycasts for it to move to the cursor

  • MouledouxMouledoux Member
    Accepted Answer

    You do not HAVE to use raycast. If you wanted the position of the cursor as it would be project to the scene from the camera, then yes, you would need raycast, but just to get a relative direction, you dont.

    See my answer to your original question for the explanation.


  • use Input.MousePosition

  • to shoot out the raycast from

  • TheLoafDudeTheLoafDude Member
    edited June 2020

    I said raycasts didn't work

    And people told me not to use raycasts

    So what can i do without raycasts?


  • ABOABO Member
    edited June 2020

    Well you have to use a ray, otherwise you can‘t tell your GameOject where where it should go.

    Look in this video at 3:13

  • WarpWarp Administrator

    Use a raycast, and get the position where you want to go.

    Just shoot a raycast from the mouse position, and record its hit position. Then, you can move your player towards that point.

    You're going to have to raycast for this, there isnt another way that is in any way elegant.

  • WarpWarp Administrator

    Also, raycasts do work. You just did not set it up, or script it properly. Raycasts are exactly what you need for a situation like this.

Sign In or Register to comment.