- Home /
Make Character swim
Hi! I am making a water level for my game, and i have been trying to make my character swim because when he enter the pool he go to to it's ground. So i have read a lot about swimming but i couldn't make it work. I have seen many people make a system like : If player is in object tagged as water, enable swim mode. If player is in swim mode, then, swim. The problem is that the First Person Character doesn't let you make the player swim or anything because it already has it's own function , but i don't want to remove it as i don't know have enough knowledge to make another one that does have the swim function or something like this.
Here is what's happening and what i want to do: Here is my current script: (I can't make it work because the character script is replacing it with it's functions)
using UnityEngine;
using System.Collections;
public class Swim : MonoBehaviour
{
bool JumpPressed = false;
public float jumpAccelleration = 3;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Water")
{
if (!JumpPressed)
JumpPressed = Input.GetKey(KeyCode.Space);
}
}
void FixedUpdate()
{
Debug.Log("SPLASH");
if (JumpPressed) GetComponent<Rigidbody>().AddForce(new Vector3(0, jumpAccelleration, 0), ForceMode.Impulse);
if (JumpPressed) JumpPressed = false;
}
}