playMaker

Author Topic: follow mouse position and raycast [SOLVED]  (Read 1222 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
follow mouse position and raycast [SOLVED]
« on: April 09, 2021, 07:45:22 PM »
I am trying unsuccessfully to follow a c# tutorial, but using playmaker.

Here is a screenshot of the code: https://ibb.co/k2XtMmg

I need to break down each of the steps and replicate them using playmaker, but it's quite confusing and I would greatly appreciate your help.

The player using their mouse control a paddle.

This paddle using a raycast is positioned either on the top or the bottom of a defined play area top of screen or bottom of the screen.

The paddle is then moved to this new position.

This paddle follows the user's input.

I have achieved to raycast in 2d, but this raycast doesn't take into account the mouse position.

I tried too use mouse follow 2d, but that's not right either.

I don't believe there is a custom action, but maybe there is?

Not to state the obvious, but I think I need this setup.

1. get the mouse position 2d. store it.

2. raycast to check where I wish to place my object.

3. update its position, using the information?

All sounds simple but beyond my limited knowledge.






 







« Last Edit: April 13, 2021, 06:30:00 PM by colpolstudios »

Weak Interactive

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 33
Re: follow mouse position and raycast
« Reply #1 on: April 09, 2021, 09:38:52 PM »
Hey, I didn't reproduce exactly what you're going for, but this should hopefully give you an idea of how to accomplish what you're trying to do (if I understood correctly).

In the attached JPEG, I have a very simple 1 state FSM attached to an object that makes that object follow the mouse around the screen.

It doesn't use ray casting, but instead "Screen To World Point." If you need it to snap to an exact position, you can use trigger colliders on the top and bottom halves of the screen to detect where the object is when you drop it, and then code it to snap to a specific position.

Of course, you'll need to program when the object follows the mouse, and when it snaps into place, etc... but hopefully this gave you the piece you were missing.

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: follow mouse position and raycast
« Reply #2 on: April 10, 2021, 10:23:06 AM »
Thank you so much for your very kind help.

It may be more helpful to link to the video that shows what I am trying to achieve, but using playmaker. https://www.youtube.com/watch?v=lPuglPBxB2s&t=206s section 12:09 - 12:14 shows the movement precisely!

In an effort to understand better I followed the tutorial and used C sharp coding.
Its available here: https://www.dropbox.com/s/f6icvg2lhsg0auz/pong_pong_extreme%20Youtube%20Thomas%20Brush.txt?dl=0

However, my floor paddle rotates incorrectly shown here: https://streamable.com/uczjhs

Possibly someone with a better understanding of coding could help resolve why the paddle within my coding is different to the movement shown in the video?

Weak Interactive

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 33
Re: follow mouse position and raycast
« Reply #3 on: April 10, 2021, 03:03:39 PM »
Hey,

Yeah, unfortunately I have no idea what I'm looking at when it comes to code; hopefully someone can help you with that.

In the meantime though, I made an example of how "Screen to World Point" can be used to mimic what was shown in the video you linked: https://drive.google.com/file/d/1pkdZNdlBkGJdm2mpcTkoxDgeWi889qUN/view?usp=sharing

The video I made is just demonstrating what it looks like. It only took me around 10 minutes to make from scratch, and I'm using the method I showed in my last post.

I have an empty object with a box trigger and rigidbody following the mouse around (using the exact FSM I showed before). I then made 4 box triggers around the screen that collide with the object following the mouse around; this lets me detect where the mouse is on screen, and then I activate a different paddle based on that. The paddles use the same "Screen to World Point" action, except just with 1 axis.

It's not perfect, but it can modified however you like, and it's very easy to set up. Again, hopefully someone can help you decipher that code, but I thought I'd share this in the meantime.

Have a great day.

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: follow mouse position and raycast
« Reply #4 on: April 10, 2021, 06:28:24 PM »
Woah thank you so much, that looks perfect.

I'm away for a few days so won't get the chance to try your idea out until I return.

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: follow mouse position and raycast
« Reply #5 on: April 13, 2021, 02:46:00 PM »
Hey,

Yeah, unfortunately I have no idea what I'm looking at when it comes to code; hopefully someone can help you with that.

In the meantime though, I made an example of how "Screen to World Point" can be used to mimic what was shown in the video you linked: https://drive.google.com/file/d/1pkdZNdlBkGJdm2mpcTkoxDgeWi889qUN/view?usp=sharing

The video I made is just demonstrating what it looks like. It only took me around 10 minutes to make from scratch, and I'm using the method I showed in my last post.

I have an empty object with a box trigger and rigidbody following the mouse around (using the exact FSM I showed before). I then made 4 box triggers around the screen that collide with the object following the mouse around; this lets me detect where the mouse is on screen, and then I activate a different paddle based on that. The paddles use the same "Screen to World Point" action, except just with 1 axis.

It's not perfect, but it can modified however you like, and it's very easy to set up. Again, hopefully someone can help you decipher that code, but I thought I'd share this in the meantime.

Have a great day.

Sent you a PM

Weak Interactive

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 33
Re: follow mouse position and raycast
« Reply #6 on: April 13, 2021, 05:42:04 PM »
Hey, saw your message and sent one back. Just in case you don't receive it for whatever reason, or if someone else is interested, here's the video showing my process: https://drive.google.com/file/d/1y4ojGuH1JQ4QAz0bKk7rzt6QsAIN_RvN/view?usp=sharing

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: follow mouse position and raycast [SOLVED]
« Reply #7 on: April 13, 2021, 06:31:16 PM »
replied to you by pm.

But thank you so much.