playMaker

Author Topic: Blur Camera on Mouse Click Game Object  (Read 8243 times)

mikeSalmond

  • Playmaker Newbie
  • *
  • Posts: 6
Blur Camera on Mouse Click Game Object
« on: July 14, 2015, 07:46:05 PM »
Hello

I've been trying to figure this out for a while, I've only been using Playmaker for a week or so and have very limited C# and Javascript skills.
 
I have a FPS game and I want to game object  trigger the camera motion blur effect when activated/clicked on.
 
So for example a player touches a drink and then gets a 'drunk' effect that would last X seconds or until perhaps they touch something else in the game that negates the effect.

I can get it to work with an onTriggerEnter script or FSM but that's not what I need.

thanks for any help, I'm using Unity 5 (which has the motion blur effect).

m

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Blur Camera on Mouse Click Game Object
« Reply #1 on: July 15, 2015, 04:56:13 AM »
Hi,
Maybe a mouse pick action?

i'm not sure what you mean exactly.

mikeSalmond

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Blur Camera on Mouse Click Game Object
« Reply #2 on: July 15, 2015, 07:45:26 AM »
Hi
Yes a mouse pick action or mouse pick event more probably (?) will 'do something when I click on the 'gameobject' but I don't know how to make that then 'do motion blur on main camera'. Is it set properties or add script or ?

So yes 'mouse pick on glass of whisky object' as a start but then how would i make the 'oh no you're drunk!" camera blur effect work? Is it set properties? I've tried a bunch of things and nothing has worked. :-(


m

flora

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Blur Camera on Mouse Click Game Object
« Reply #3 on: July 15, 2015, 08:08:29 AM »

hello  :)

you could have 2 cameras, one for the sober state and one for the drunken state (with all the effects you want applied on it) ... and switch between them anyways you like


terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: Blur Camera on Mouse Click Game Object
« Reply #4 on: July 15, 2015, 08:58:18 AM »
add the blur to the camera, then drag the blur component to playmaker, and use set property to enable/disable the blur when the mousepick happens

mikeSalmond

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Blur Camera on Mouse Click Game Object
« Reply #5 on: July 15, 2015, 03:52:15 PM »
thanks flora and terri....
 I'd not thought of the 2 camera setup, that might work I'll try it out - also unsure about that suggestion from Terri, I think I tried that already and it didn't work because that does make some logical sense. :-)

mikeSalmond

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Blur Camera on Mouse Click Game Object
« Reply #6 on: July 15, 2015, 05:25:30 PM »
OK I tried the Switch Camera option but it's an FPS so the only way I could find to get that to work was to have a camera outside of the FPS controller and a 'blur cam'.
But if I have a cameara that's not part of the FPSController it doesn't control well at all?
Unity 5 doesn't seem to like switching between cams unless you disable the first cam (the FPS Controller camera) so that means the player can't move. Unless I'm doing something wrong?

I also tried using the blur on the camera thing but as it's a camera in the first person controller it won't apply the settings to a camera within a game object, because I guess it's not a 'camera' but something else?

 I found a script online via a tutorial that does camera blur with a TriggerObject function and that works great but I need it to work from selecting a gameobject not walking into a trigger area.

So this but with a mouse-event from an object.

thanks for any help!

m



flora

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Blur Camera on Mouse Click Game Object
« Reply #7 on: July 16, 2015, 08:12:08 AM »

try this set up :

Create an empty game object and call it FPScontroller
=> Put all the controller scripts and stuffs (rigidbody, collider, ...) on this game object
=> Put Cam1 and Cam2 as childs of the FPScontroller game object
=> enable/disable the Cam you need

and Voila !

mikeSalmond

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Blur Camera on Mouse Click Game Object
« Reply #8 on: July 17, 2015, 08:03:46 AM »
thx for the idea flora but it doesn't really work. The issue is also that having a camera that's a child of the FPSController (even with all the bells and whistles) disrupts the controls, so for example when you have a FPS character created 'normally' the movement buttons are mapped correctly for up-down-left-right and the mouselook also works. As a child in this way none of that works. Of course that's all fixable, but it's creating more problems on top of the ones I already had :-(

I just can't believe there's not a better, more elegant way of doing something like this using Playmaker that doesn't involve swapping cameras? In Unity5?

thx to everyone for any suggestions!

m

mikeSalmond

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Blur Camera on Mouse Click Game Object
« Reply #9 on: July 17, 2015, 10:11:41 AM »
OK so the solution I'm using is outside of playmaker - a script that's cobbled together from online tutorials. Modifying a script from
http://speed-tutor.com/scripts/

it works, but now i have to find a way to make it incremental, a 'drunkeness' that occurs over time...... :-)

#pragma strict

var testObj : GameObject;

private var canHover : boolean = false;
private var mBlur : UnityStandardAssets.ImageEffects.MotionBlur;


function Start()
{
   mBlur = GameObject.Find("FPSController").GetComponent(UnityStandardAssets.ImageEffects.MotionBlur);
   mBlur.enabled = false;
}

function Update()
{
    var fwd = transform.TransformDirection(Vector3.forward);
    var hit : RaycastHit;
   
   if (Physics.Raycast(transform.position, fwd, hit))
    {
       if(hit.distance <= 5.0 && hit.collider.gameObject.tag == "pickup")
       {
          if(Input.GetMouseButtonDown(0))
          {
          mBlur.enabled = true;
         mBlur.blurAmount = 60;
      }

       }
 
       }
}


flora

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Blur Camera on Mouse Click Game Object
« Reply #10 on: July 17, 2015, 11:48:07 AM »
Quote
As a child in this way none of that works

i use this setup for myself all the time, and it works pretty fine  :)
you just have to put all the controller scripts and the rigidbody on the empty game object, not the cam ... you also need to check X, Y and Z in the "Freeze the Rotation" tab (Rigidbody > Constraints) ... sometimes i need also to check Y in the "Freeze the Position" tab.

if you want to go with 1 cam, and just enable/disable the blur effect ... then Terri gave you the answer a long time ago  :)
« Last Edit: July 17, 2015, 11:55:34 AM by flora »

terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: Blur Camera on Mouse Click Game Object
« Reply #11 on: July 17, 2015, 12:59:58 PM »
I also tried using the blur on the camera thing but as it's a camera in the first person controller it won't apply the settings to a camera within a game object, because I guess it's not a 'camera' but something else?

Ok. So you have your camera selected in the hierarchy, then go to Component>Image Effects>Blur>Motion Blur to add the blur script. Then you drag the script from the inspector into the FSM's state, and select Set Property. There you select Enable from the dropdown and set the checkbox to true or false.

You can also set the blur amount with a float.