playMaker

Author Topic: Object Rotation To Mouse Location[SOLVED]  (Read 9696 times)

Jtheme

  • Playmaker Newbie
  • *
  • Posts: 19
Object Rotation To Mouse Location[SOLVED]
« on: January 01, 2013, 06:41:01 PM »
I am trying to find a way to make a game object rotate on the x-axis in the location of the mouse pointer.

Any help or tips would be greatly appreciated!
« Last Edit: January 07, 2013, 03:14:45 AM by jeanfabre »

Jtheme

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Object Rotation To Mouse Location
« Reply #1 on: January 02, 2013, 01:39:58 AM »
Maybe I'm not explaining myself well enough.  I am wanting to rotate an object exactly how the player rotates in the scene http://u3d.as/content/unity-technologies/angry-bots/2aL


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Object Rotation To Mouse Location
« Reply #2 on: January 02, 2013, 06:03:03 AM »
Hi,

 interesting question:

 study this mouse drag action ( that let you know the position of the mouse in the 3d world on a plane)
http://hutonggames.com/playmakerforum/index.php?topic=272.0

using the resulting position with the above action, you can then use the action "Smooth Look at"
https://hutonggames.fogbugz.com/default.asp?W458

That's would be the right combination to begin with this.

bye,

 Jean

Jtheme

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Object Rotation To Mouse Location
« Reply #3 on: January 02, 2013, 11:19:28 AM »
Thanks Jean!

I have one more question.  I'm not sure how to go about this at all. 

How would I go about making an even when the object reaches Y-axis 180 and then another event when it reaches Y-axis 90?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Object Rotation To Mouse Location
« Reply #4 on: January 02, 2013, 02:42:31 PM »
Hi,

 the angle is between what and what?

there is an action "Get angle to target":
https://hutonggames.fogbugz.com/default.asp?W494

Try this, and then simply compare the angle using "float compare" or float switch and then you can fire events like that.

 bye,

 Jean

Jtheme

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Object Rotation To Mouse Location
« Reply #5 on: January 02, 2013, 03:14:11 PM »
Thank you, I'm pretty new at this.  How exactly would I go about that?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Object Rotation To Mouse Location
« Reply #6 on: January 03, 2013, 07:33:10 AM »
Hi,

 ok, please find a package attached where the gameObject will look at the mouse like on angrybots.

 As for the angle events, I am still unsure what you are trying to achieve, so can you be more explicit?

bye,


 Jean

Jtheme

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Object Rotation To Mouse Location
« Reply #7 on: January 03, 2013, 11:17:47 AM »
To explain, I have a scene with a red cylinder with a blue cube as it's face.  I have it's rotation following my mouse.
When my mouse gets in the angles of the blue area "event 1" for example it fires off an even.  And when my mouse gets in the green area it fires off a different event.


KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Object Rotation To Mouse Location
« Reply #8 on: January 03, 2013, 03:53:47 PM »
Hi

I am by no means an expert at this, but if i was you, I would create an invisible game object at the green and blue area, and then make each of them a hitbox that covers the area where you want to trigger an event

then on the red cylinder that you are rotating, add a raycast to the front of it, and if it hits an object, make it store the name of that object in a variable - then use that variable to run a compare between the name of the object the ray hit, and the name of the actual box. If the names are the same, fire off an event.

Hope this helps

-Kozgal
« Last Edit: January 03, 2013, 03:56:05 PM by KozTheBoss »
Remember, you don't fail unless you give up trying to succeed!

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Object Rotation To Mouse Location
« Reply #9 on: January 03, 2013, 04:25:41 PM »
reading through this again, what i said above would only work if the red object doesn't move (only rotates)

If the object moves as well as rotates, then i guess you use a get rotation action and save the rotation coords as a float or int and do a compare with a variable you set

I could give an example if you could explain what this is used for - is it the player thats able to move and if he looks to much to the side, something happens?
Remember, you don't fail unless you give up trying to succeed!

Jtheme

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Object Rotation To Mouse Location
« Reply #10 on: January 03, 2013, 10:55:41 PM »
Yes it if for my player.  When he looks to the side I'm wanting to trigger a unique animation.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Object Rotation To Mouse Location
« Reply #11 on: January 04, 2013, 02:48:38 AM »
hi,

 Simply attach the collider to your player then. Have a trigger collider for the front section and a trigger collider for the back section, as the blue box rotates, you simply wait for trigger events and fire when entered.

bye,

 Jean

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Object Rotation To Mouse Location
« Reply #12 on: January 05, 2013, 09:15:33 AM »
Exactly what Jean said :) to explain it in "normal" words - you make two invisible gameobjects and parent them to the player (so they always follow the player) then you add collider components to both of those invisible gameobjects and check the "make trigger" button in the component menu. Now play around with position and size so that the two trigger boxes are located on the side of the character in the area you want to trigger an event. Make sure the trigger boxes only follow player position and not the rotation (otherwise when player rotates, the boxes will rotate with him and not be able to detect rotation at all)

When the triggerboxes are set, you can do 1 of 2 things;

Either add a 3rd trigger box to the front of the character that also rotates with character (so the box is always on the front of the character - like a reverse backpack) and make the side-triggers listen for collision with the front-trigger. This will detect that the character has turned to the side, and trigger an event (like your animation)

or
Do the same thing, but with raycast.
Add a raycast to the front of the character - detect if the raycast hits the side-trigger objects and if so, trigger an event

Hope this helps you understand Jeans pro lingo :)

-Koztheboss
Remember, you don't fail unless you give up trying to succeed!

Jtheme

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Object Rotation To Mouse Location
« Reply #13 on: January 05, 2013, 11:21:22 AM »
I got it to work!  Thank you to everyone that helped out!!!  I've been trying to figure out how to do this for weeks.

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Object Rotation To Mouse Location
« Reply #14 on: January 05, 2013, 03:27:39 PM »
glad to help :)
Remember, you don't fail unless you give up trying to succeed!