JacobDSiler
Member
I have started making a custom swim and deep diving ability for the UCC Third person view.
The character currently starts swimming when he enters a collider on the Water layer. He doesn't have any locomotion system yet, and I am not sure how physics work in TPC ability code to simulate the drag of water. Perhaps I can just use the built in physics, but I'm just not sure if the PlayerLocomotion (and other movement) system(s) will conflict with normal physics methods. I suspect that they do, though I could easily be wrong.
I simply want to make him add a slow forward motion according to his input vector when he is swimming and have that same force slowly decelerate as he changes directions so he reacts as if he's underwater. The drifting factor is important, and so is the drag factor, and I'm not sure how to program those physics.
Here is some pseudo code:
Obviously I have not been able to figure out the objects in the namespace quite enough yet, but I think you can understand my desired outcome by the pseudo code.
Thanks for all help offered.
Jacob Siler
The character currently starts swimming when he enters a collider on the Water layer. He doesn't have any locomotion system yet, and I am not sure how physics work in TPC ability code to simulate the drag of water. Perhaps I can just use the built in physics, but I'm just not sure if the PlayerLocomotion (and other movement) system(s) will conflict with normal physics methods. I suspect that they do, though I could easily be wrong.
I simply want to make him add a slow forward motion according to his input vector when he is swimming and have that same force slowly decelerate as he changes directions so he reacts as if he's underwater. The drifting factor is important, and so is the drag factor, and I'm not sure how to program those physics.
Here is some pseudo code:
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
public class Swim : DetectObjectAbilityBase
{
//Input makes the character swim.
public override void ApplyPosition perhaps?()
{
//Add drag and simulate water physics.
[Pseudo Code]
Var M = the appropriate input magnitude (Normal, with Speed Change for example);
Apply force in the forward vector by M.
Add Drift to the character.
base.ApplyPosition Or whichever method I should override();
}
//We want to stop swimming when the character exits the water trigger bounds.
public override void OnTriggerExit(Collider other)
{
//Stopping the ability
if (other.gameObject == m_DetectedObject) {
StopAbility();
}
base.OnTriggerExit(other);
}
}
Obviously I have not been able to figure out the objects in the namespace quite enough yet, but I think you can understand my desired outcome by the pseudo code.
Thanks for all help offered.
Jacob Siler