- Home /
Modifing Standard Assets FPC to swim
I have found many similar questions to this one, most of them have no answers or just theoretical guidelines.
I used the First Person Controller (Using Character Controller not the rigid body version) prefab provided in Unity's Standard Assets Pack. I have not modified it in anyway as of yet, except for adding an empty child with a sphere collier set to isTrigger. This object was moved up on the y-axis to represent the head. I attached a script to the head that checks if I entered and exited the water. This all works, now I just need the "physics" of swimming, if I was using a rigid body I could just toggle the gravity off and on when I enter and exit the water. I'm not really too concerned with swimming backwards or sideways. Just forward in the way the player is facing.
I have read that using CharaterController.Move();
instead of CharaterController.SimpleMove();
should fix the problem. However that does not seem to be a quick modification as the script provided by unity seems to rely on the CollisionFlags returned by CharaterController.Move();
So before I scrutinize every line of code, of rewrite my own controller, I thought someone might have a quick and sensible solution? I don't need a super complex swimming system, just basically need to turn the gravity off and on.
Here's my trigger code if you want to reference it:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.ImageEffects;
public class SwimController : MonoBehaviour
{
public BlurOptimized blur;
public GameObject colorOverlay;
private bool isSwimming;
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Water")
{
// player entered water
blur.enabled = true;
colorOverlay.SetActive(true);
}
}
public void OnTriggerExit(Collider other)
{
if (other.tag == "Water")
{
// player exited water
blur.enabled = false;
colorOverlay.SetActive(false);
}
}
}
Your answer
Follow this Question
Related Questions
Unity 5, script for a character to be able to swim in water 1 Answer
Charactercontroller.move affecting rotation 1 Answer
Problem with CharacterController.SimpleMove 0 Answers
Any way to disable SimpleMove's sliding? 1 Answer
Unity StandardAssets CrossPlatformInput (MobileInput Buttons) for Crouching issues 0 Answers