playMaker

Author Topic: Locking game object rotation/upVector to mouse position  (Read 6947 times)

upOwlNight

  • Playmaker Newbie
  • *
  • Posts: 27
Locking game object rotation/upVector to mouse position
« on: January 20, 2012, 04:35:53 PM »
What I want: I want to make a side scroller. The camera is on top looking down at my space ship. I want my space ships up vector, or nose, to face my mouse position.

Thoughts: After trying everything I could think of, I feel I got the closest when I stored my Ships Vector3 to a variable called shipPosition.
I used the action in an FSM connected to my ship called Vector3 Rotate Towards.
For Current Direction i added my variable "shipVector"
For Target Direction all I want to do is put in variables for x, y, and z. Why can't I do that?

I stored my MouseX and MouseY into global variables called mouseX and mouseY. I don't see the reasoning in not allowing me to call them instead of typing just one number. Sure, this is on option for a variable, but it HAS to be vector3, and I can't figure out how to get that more my mouse.

This honestly sounds like something that has to be done all the time, there HAS to be something built in playmaker, but i've searched everything.

Please keep in mind when offering advice, the camera will not be rotating or moving at all with the rotation of the ship. I cant just lock camera to mouse or something.

Thanks for reading. I'm looking forward to hearing replies. Sorry for the length, I wanted to be thorough.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Locking game object rotation/upVector to mouse position
« Reply #1 on: January 24, 2012, 02:01:32 AM »
Hi,

I created a custom actions that allows you to track mouse position on a plane defined in the world.

http://hutonggames.com/playmakerforum/index.php?topic=272.0

So basically, you set up this action with the "plane" on the XZ axis of your ship ( or the world XZ if you want since it's the same in your case).

 then the action will return you the position of the mouse on that XZ plane, you can then have your ship look at this position.

 Done,

If in trouble, let me know.


 Bye,

 Jean

upOwlNight

  • Playmaker Newbie
  • *
  • Posts: 27
Re: Locking game object rotation/upVector to mouse position
« Reply #2 on: January 31, 2012, 06:02:10 PM »
JEAN! the way you and Alex help people on the forums is blowing my mind! You guys are gods.

I'm glad you had the time to respond to me. I've been on vacation, but back at it again now. I've read through all the forums and other post links that branched off of the one you gave me, but I think here's my biggest problem: I have no experience in Unity3d. When I see these scripts I get very intimidated. I'm never quite sure what to be adding them to, and then how to properly manipulate them.

All I need to figure out is how to store the mouse position into a variable, and then make a gameObject rotate to face that object constantly. I would then use, say "w" to thrust in the position the ship is facing. I couldn't figure out how you stored these coordinates with the package you linked me to. I've been at it all day!

I feel a bit embarrassed that there isn't another single person out there trying to figure out what I am... It makes me think it is sooooo basic that it is just looked over, yet I missed it.

ok, last thing, and from here on out any replies from me will be short and to the point, I swear.

I used "get mouse x" and "get mouse y" to store to variable "mouse x" and "mouse y" in an FSM on a empty game object called "mouse info"

Next I made a global variable called "mouse vector" and used "get vector3 XYZ" and input "mouse x" and "mouse y". Left z blank. This looked like a setup you had made.

I then went to my ship and tried all kinds of actions: look at, rotate to, set rotation, and even messed around with converting vector3 to angles. I used the global variable, "mouse vector" as the position to look at.

The best result I could come up with is a ship that rotates 15 degrees either way, but will not lock on to my mouse. It just slightly rotates back and forth a little bit :(.

Is there really not a simple way to have an object face the mouse without using custom scripts?

I'll be trying to figure it out while I wait. If I get it, i'll post my solution. Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Locking game object rotation/upVector to mouse position
« Reply #3 on: February 01, 2012, 02:46:51 AM »
Hi,

 Thanks for your kind words :)


 Object facing the mouse will required fiddling, with our without playmaker. I am not aware of any framework or ready made script for this ( haven't search hard tho).

I'll try to do a package that just do that over the week end. So Stay tune.

Basically, it will work like so: I will use this action with a plane facing the camera, so I will get the mouse position on that plane, then I will make the gameObject looking at the position. The "trick" will be to properly extract the camera transform position and rotation to orient the plane properly as the camera moves.

Nothing is basic, at least it's just a point of view... it's as you learn how to do things that you start to feel more confortable implementing features and specific needs. If you never worked with transforms for example, even the slightest need becomes an effort.


 Bye,

 Jean
 

upOwlNight

  • Playmaker Newbie
  • *
  • Posts: 27
Re: Locking game object rotation/upVector to mouse position
« Reply #4 on: February 01, 2012, 02:43:04 PM »
I really appreciate the help man. I'm going to suck it up and invest some time into learning more of unity. There's never an easy way around anything it seems. I was playing in GameSalad before I found Playmaker; It's pretty amazing how much goes into something that "seems" simple. I guess all hard work done by a game dev, or programmer will go un-noticed by the common folk :P.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Locking game object rotation/upVector to mouse position
« Reply #5 on: February 09, 2012, 01:25:44 AM »
Hi,

 Sorry, was unavailable until today, so I'll tackle this within the next few days.

 Bye,

 Jean