The legacy UFPS forums are in read only mode. Please upgrade to version 2 for continued support.

Swimming Trigger

2»

Comments

  • Pocheson Posts: 23Member


    A video demonstrating the swimming trigger

    This is a very simple implementation demonstrating how to use the free fly mode to make a player start swimming when the player enters the trigger. This should be placed on an object that has a collider with trigger enabled.

    This mod comes with presets for the vp_FPController, vp_FPCamera and vp_FPWeapon. For this to function properly these presets must be used. Feel free to tweak them as you see fit. They are courtesy of @Cal.

    Instead of creating the states for the above presets on each component, you can use the Component Preset Browser and all the work will be done for you :)

    Download (4 KB)

    p.s. Also note that the presets were setup for another game I was working on where the player was taller than the default one setup in UFPS, so some tweaking of the camera preset (and possibly the others) may be in order.

    Link to download swimming trigger don't work, can u fix it?
    Anyone can give me download link swimming trigger?
  • Ryan199gamer Posts: 20Member

    Can an animation be played and the weapon disabled when I enter the water?

    I see no reason why not, since the script was originally designed to be on a water collider.
    @BrandSpankingNew Like a set of animations, forward, backward, left, right etc.

    and could you kindly post a example code because this UFPS is not really friendly for a noob like me.
  • genocidedolphinsgenocidedolphins Posts: 599Member, MPTester
    would make sense to buy and use suimono for this, theyve basically done it, just need to work out how to make it work on a ufps guy.
    Radiant Silver Labs - one man indie band, developing Genocide Dolphins
    Looking for an Android freelancer? Look no further: www.garethmurfin.co.uk
  • SeanSteezySeanSteezy Posts: 66Member

    would make sense to buy and use suimono for this, theyve basically done it, just need to work out how to make it work on a ufps guy.

    Yeah if you ever get suimono working with UFPS I'd love to know how you go about it. I have it too but never really got to that point yet....
  • Pocheson Posts: 23Member
    Anyone has a Swimming Trigger? Please post link to download it.
  • redhawkredhawk Posts: 492Member, MPTester
    I have the script and presets. Let me tweak it a bit and I will post the script here in the forum and a video how to.
  • redhawkredhawk Posts: 492Member, MPTester
    Below are the Swimming Scripts and Presets that the VisionPunk team (and Patrick in particular) created. Note these were created by VisionPunk and all rights are reserved.

    Swimming Triggerer Script
    /////////////////////////////////////////////////////////////////////////////////
    //
    // vp_SwimmingTrigger.cs
    // © VisionPunk. All Rights Reserved.
    // https://twitter.com/VisionPunk
    // http://www.visionpunk.com
    //
    // description: A very simple implementation demonstrating how to use the free
    // fly mode to make a player start swimming when the player enters
    // the trigger. This should be placed on an object that has a
    // collider with trigger enabled
    //
    /////////////////////////////////////////////////////////////////////////////////

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;

    public class vp_SwimmingTrigger : MonoBehaviour
    {

    public LayerMask LayerMask = 1 << vp_Layer.LocalPlayer; // layer mask to check for
    public string StateName = "Swimming";

    protected static string m_IsPlayerKey = "Is Player"; // key for checking if the collider is the player
    protected static string m_PlayerKey = "Player"; // key for the vp_FPPlayerEventHandler


    protected virtual void Start()
    {

    collider.isTrigger = true;

    }


    /// <summary>
    /// Check if this object is in the layer mask
    /// and if so, start swimming
    /// </summary>
    protected virtual void OnTriggerEnter( Collider col )
    {

    Dictionary<string, object> data = GetDataForCollider(col);
    if( !((bool)data[m_IsPlayerKey]) )
    return;

    vp_FPPlayerEventHandler player = (vp_FPPlayerEventHandler)data[m_PlayerKey];
    player.SetState(StateName);
    player.MotorThrottle.Set(Vector3.zero);
    player.Jump.TryStop();
    Vector3 softForce = new Vector3(0, player.Velocity.Get().normalized.y * .25f, 0);
    player.Stop.Send();
    player.GetComponent<vp_FPController>().AddSoftForce(softForce, 10);

    }


    /// <summary>
    /// Check if this object is in the layer mask
    /// and if so, stop swimming
    /// </summary>
    protected virtual void OnTriggerExit( Collider col )
    {

    Dictionary<string, object> data = GetDataForCollider(col);
    if( !((bool)data[m_IsPlayerKey]) )
    return;

    vp_FPPlayerEventHandler player = (vp_FPPlayerEventHandler)data[m_PlayerKey];
    player.SetState(StateName, false);

    }


    /// <summary>
    /// This method just does some checking to see if the object is in the mask
    /// and if so if it has a vp_FPPlayerEventHandler component and then returns
    /// the data
    /// </summary>
    protected virtual Dictionary<string, object> GetDataForCollider( Collider col )
    {

    // check if collider is in layermask
    if((LayerMask.value & 1 << col.gameObject.layer) == 0)
    return new Dictionary<string, object>(){ { m_IsPlayerKey, false } };

    // check if player component exists
    vp_FPPlayerEventHandler player = col.gameObject.GetComponent<vp_FPPlayerEventHandler>();
    if(player == null)
    return new Dictionary<string, object>(){ { m_IsPlayerKey, false } };;

    // send data. includes player.
    return new Dictionary<string, object>(){ { m_IsPlayerKey, true }, { m_PlayerKey, player } };

    }

    }


    CameraSwimming Preset
    ///////////////////////////////////////////////////////////
    // Component Preset Script
    ///////////////////////////////////////////////////////////

    ComponentType vp_FPCamera
    RenderingFieldOfView 60
    RenderingZoomDamping 0.2
    PositionOffset 0 1.75 0.1
    PositionGroundLimit 0.1
    PositionSpringStiffness 0.01
    PositionSpringDamping 0.25
    PositionSpring2Stiffness 0.95
    PositionSpring2Damping 0.25
    PositionKneeling 0.1 // <---- modified
    PositionKneelingSoftness 1
    PositionEarthQuakeFactor 1
    RotationPitchLimit 90 -90
    RotationYawLimit -360 360
    RotationSpringStiffness 0.01
    RotationSpringDamping 0.25
    RotationKneeling 0.025
    RotationKneelingSoftness 1
    RotationStrafeRoll -1 // <---- modified
    RotationEarthQuakeFactor 0
    ShakeSpeed 0.1 // <---- modified
    ShakeAmplitude 20 20 1 // <---- modified
    BobRate 0.5 1 0 0.5 // <---- modified
    BobAmplitude 1 0.25 0 0.5 // <---- modified
    BobInputVelocityScale 1
    BobMaxInputVelocity 100
    BobRequireGroundContact False // <---- modified (new)
    BobStepThreshold 10


    ControllerSwimming Preset
    ///////////////////////////////////////////////////////////
    // Component Preset Script
    ///////////////////////////////////////////////////////////

    ComponentType vp_FPController
    MotorAcceleration 0.09 // <---- modified
    MotorDamping 0.062 // <---- modified
    MotorAirSpeed 0.35
    MotorSlopeSpeedUp 1
    MotorSlopeSpeedDown 1
    MotorFreeFly True // <---- modified (new)
    MotorJumpForce 0.11
    MotorJumpForceDamping 0.08
    MotorJumpForceHold 0.003
    MotorJumpForceHoldDamping 0.5
    PhysicsForceDamping 0.05
    PhysicsPushForce 5
    PhysicsGravityModifier 0
    PhysicsSlopeSlideLimit 30
    PhysicsSlopeSlidiness 0.15
    PhysicsWallBounce 0
    PhysicsWallFriction 0
  • redhawkredhawk Posts: 492Member, MPTester
    edited July 2015
    I created the below script to use with the above pieces and to go along with the Tutorial posted below. This script is to handle effects and it's below the Video. You can probably swap out the references here to point to some other effects (like Sunomi water which I don't own).


    https://youtu.be/x8sDjsJemQk

    Water Effect Script
    using UnityEngine;
    using System.Collections;
    using UnityStandardAssets.ImageEffects;//Need this namespace reference to be able to reference the ImageEffects

    namespace red
    {
    public class red_InWater : MonoBehaviour {

    //Below are just examples. Other options could be to turn on/off Fog, but I like ImamgeEffects better
    public BlurOptimized blurScript=null; //I Put this on the Weapon Camera so the weapon is blurred
    public ColorCorrectionCurves colorScript=null; //I Put this on the FPSCamera

    //Layer for the Player
    public LayerMask playerLayer = 1 << vp_Layer.LocalPlayer; // layer mask to check for
    vp_FPCamera m_camera=null;

    void OnTriggerEnter(Collider col)
    {
    //First check to see if whatever collided is in the layer mask. If not, return
    if((playerLayer.value & 1 << col.gameObject.layer)==0)
    return;
    m_camera=col.gameObject.GetComponentInChildren<vp_FPCamera>();
    TurnOn();
    }
    void OnTriggerExit(Collider col)
    {
    //First check to see if whatever collided is in the layer mask. If not, return
    if((playerLayer.value & 1 << col.gameObject.layer)==0)
    return;
    m_camera=col.gameObject.GetComponentInChildren<vp_FPCamera>();
    TurnOff();
    }

    void TurnOff()
    {
    //Do your specific stuff here to disable things
    blurScript=m_camera.GetComponentInChildren<BlurOptimized>();
    blurScript.enabled=false;
    colorScript=m_camera.GetComponentInChildren<ColorCorrectionCurves>();
    colorScript.enabled=false;
    }
    void TurnOn()
    {
    //Do your specific stuff here to enable things
    blurScript=m_camera.GetComponentInChildren<BlurOptimized>();
    blurScript.enabled=true;
    colorScript=m_camera.GetComponentInChildren<ColorCorrectionCurves>();
    colorScript.enabled=true;
    }
    }
    }
  • Pocheson Posts: 23Member
    redhawk said:

    I created the below script to use with the above pieces and to go along with the Tutorial posted below. This script is to handle effects and it's below the Video. You can probably swap out the references here to point to some other effects (like Sunomi water which I don't own).


    https://youtu.be/x8sDjsJemQk

    Water Effect Script
    using UnityEngine;
    using System.Collections;
    using UnityStandardAssets.ImageEffects;//Need this namespace reference to be able to reference the ImageEffects

    namespace red
    {
    public class red_InWater : MonoBehaviour {

    //Below are just examples. Other options could be to turn on/off Fog, but I like ImamgeEffects better
    public BlurOptimized blurScript=null; //I Put this on the Weapon Camera so the weapon is blurred
    public ColorCorrectionCurves colorScript=null; //I Put this on the FPSCamera

    //Layer for the Player
    public LayerMask playerLayer = 1 << vp_Layer.LocalPlayer; // layer mask to check for
    vp_FPCamera m_camera=null;

    void OnTriggerEnter(Collider col)
    {
    //First check to see if whatever collided is in the layer mask. If not, return
    if((playerLayer.value & 1 << col.gameObject.layer)==0)
    return;
    m_camera=col.gameObject.GetComponentInChildren<vp_FPCamera>();
    TurnOn();
    }
    void OnTriggerExit(Collider col)
    {
    //First check to see if whatever collided is in the layer mask. If not, return
    if((playerLayer.value & 1 << col.gameObject.layer)==0)
    return;
    m_camera=col.gameObject.GetComponentInChildren<vp_FPCamera>();
    TurnOff();
    }

    void TurnOff()
    {
    //Do your specific stuff here to disable things
    blurScript=m_camera.GetComponentInChildren<BlurOptimized>();
    blurScript.enabled=false;
    colorScript=m_camera.GetComponentInChildren<ColorCorrectionCurves>();
    colorScript.enabled=false;
    }
    void TurnOn()
    {
    //Do your specific stuff here to enable things
    blurScript=m_camera.GetComponentInChildren<BlurOptimized>();
    blurScript.enabled=true;
    colorScript=m_camera.GetComponentInChildren<ColorCorrectionCurves>();
    colorScript.enabled=true;
    }
    }
    }

    Nice video. Can you post "WaterTemp" material or tell me how i can create this too.
    Thanks in advice.
  • dustinwloring1988dustinwloring1988 Posts: 142Member, MPTester
    have you tried the vortex script for when your in the water
    Dustin Loring
    www.BuckeyeStudios.com
  • redhawkredhawk Posts: 492Member, MPTester
    Vortex set at 15 to 25 is nice. Of course it would be super easy to add to the above script and anyone should be able to figure that part out now.
  • Pocheson Posts: 23Member
    edited July 2015
    redhawk said:

    Vortex set at 15 to 25 is nice. Of course it would be super easy to add to the above script and anyone should be able to figure that part out now.

    When i enter to water - water effect "ColorCorrectionCurves" not enabled and give me error on "red_inwater" script - 40 and 48 lines.

  • redhawkredhawk Posts: 492Member, MPTester
    I've tested this multiple times and had no errors before I posted it. I have that script on my FPS Camera and the other script is on the Weapon Camera. Both are Disabled to start. I have no idea why you would get errors. I even set the script up so that if the particular script (color curves) is not present, then it will ignore that part.

    I suggest that you double check that your player is set up correctly. Mine is on the LocalPlayer layer and the Player tag. Then my Water effect trigger is on the Water layer and the script is looking for the LocalPlayer layer.
  • ArnessoMusicArnessoMusic Posts: 79Member
    Hi
    Swimming triger works, but I have problem, when I move camera it after camera is stopped and freezed i get this error :
    "GUI Window tries to begin rendering while something else has not finished rendering! Either you have a recursive OnGUI rendering, or previous OnGUI did not clean up properly."

    Do you have idea ? :(
  • Evan Posts: 50Member, MPTester
    I decided to give this a shot with the new Aquas water plug-in. First thing I noticed is their camera FX setup instantly creates the FX when in the water. Which is really cool... If you guys have not seen it yet it is by far the best water plug-in I have seen for Unity yet. AQUAS Water Set

    I had to create a separate box collider to set the vp_SwimmingTrigger states. The problem I am having now is the player walks into the water and only starts swimming if you jump. So seems there is a conflict if you are still touching the terrain. It will also resort back to walking if you swim then bump into the terrain. Has anyone else had this problem and found a work around for this?
  • Evan Posts: 50Member, MPTester
    edited March 2016
    Here is a quick video showing how awesome this Aquas water is!

    Aquas Example

    This is also using the mobile shaders. So if you are using this for desktop it's even better looking. I have my quality settings for this on simple.
  • BrandSpankingNewBrandSpankingNew Posts: 2,374Member, MPTester
    That looks really good. Thanks for showing it.
    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
  • TryThisTryThis Posts: 985Member
    Yes, that's an interesting product!
  • Evan Posts: 50Member, MPTester
    It's very well done. The setup for the cameras is automatic so no need to fiddle with FX etc. I've sent the developer a message and asked him to join the forums. I think the community would love to see something like this fully supporting UFPS.
  • genocidedolphinsgenocidedolphins Posts: 599Member, MPTester
    For sure, if he could swim when he goes in it would rock.. looks good though. I am amazed the Suimono guy hasnt tacked on UFPS support yet.
    Radiant Silver Labs - one man indie band, developing Genocide Dolphins
    Looking for an Android freelancer? Look no further: www.garethmurfin.co.uk
  • metaldc4life Posts: 5Member
    nomax5 said:

    I forgot to mention your game looks amazing and actually looks like a working game, I am so far behind I dont have even have a UI yet.

    That's really awesome!!
    Keep up the good work man! =)
  • genocidedolphinsgenocidedolphins Posts: 599Member, MPTester
    Evan said:

    Here is a quick video showing how awesome this Aquas water is!

    Aquas Example

    This is also using the mobile shaders. So if you are using this for desktop it's even better looking. I have my quality settings for this on simple.

    Looks very nice!! Im going to try this tonight I think!!
    Radiant Silver Labs - one man indie band, developing Genocide Dolphins
    Looking for an Android freelancer? Look no further: www.garethmurfin.co.uk
  • genocidedolphinsgenocidedolphins Posts: 599Member, MPTester
    Got it working with Aquas, looks great but it requires deferred rendering, so looks like Im looking for yet another water solution, all the underwater and motor free fly stuff works, it's awesome, probably don't even need arms.
    Radiant Silver Labs - one man indie band, developing Genocide Dolphins
    Looking for an Android freelancer? Look no further: www.garethmurfin.co.uk
Sign In or Register to comment.