|
Post by rbm on Feb 16, 2017 8:31:11 GMT
Hi
how can I add the flying ability?
for example I want to when player pres "X" button , the character Separated from the ground and after that fly in sky with same controller . Flying length is as much as Stamina!
***
I mean after pressing "X" the character Float in the sky
and the Idle Animation become flying animation for every different characters . and Also character be able to fly higher by pressing Space and lower with "C" !
Specially for 2D and 2.5D Games! **** Sorry for my bad English! Using Goggle Translate !
|
|
|
Post by sickscore on Feb 16, 2017 13:14:57 GMT
Hey,
I'm currently working on this for a project. Here are some snippets and steps to reproduce.
vThirdPersonInput.cs - Create 3 new GenericInput's:
public GenericInput flyInput = new GenericInput("X", "X", "X"); public GenericInput flyUpInput = new GenericInput("Space", "X", "X"); public GenericInput flyDownInput = new GenericInput("C", "X", "X"); - Create a method for handling your input:
protected virtual void FlyInput () { if (flyInput.GetButtonDown ()) cc.Fly ();
if (flyUpInput.GetButton ()) cc.flyDirection = 1; // raise else if (flyDownInput.GetButton ()) cc.flyDirection = -1; // sink else cc.flyDirection = 0; // reset }
vThirdPersonController.cs - Add Fly method
public virtual void Fly () { if (animator.IsInTransition (0)) return;
// know if has enough stamina to make this action bool staminaConditions = currentStamina > flyStamina;
// conditions to do this action bool flyConditions = !isCrouching && !actions && staminaConditions;
// return if flyConditions is false if (!flyConditions) return;
// trigger fly behaviour isFlying = true; isJumping = false;
// trigger fly animations if (speed < 0.1f) animator.CrossFadeInFixedTime ("Fly", 0.1f); else animator.CrossFadeInFixedTime ("FlyMove", 0.05f);
// reduce stamina ReduceStamina (flyStamina, false); currentStaminaRecoveryDelay = 1f; }
vThirdPersonMotor.cs - Create variables:
[Tooltip("Velocity applied to the rigidbody while mid-air")] public float flyVelocity = 20f; [HideInInspector] public int flyDirection = 0; // 1 = up | -1 = down - Add method to control the fly behaviour
#region Fly Methods protected void ControlFlyBehaviour() { if (!isFlying) return; _rigidbody.useGravity = false;
// interrupt flying when out of stamina or grounded/crash-landed :) if (currentStamina <= 0f || isGrounded) { isFlying = false; return; }
// raise / sink while flying // NOTE: Just for testing, not finished ;) float flyVel = 0f; if (flyDirection != 0) { flyVel = (flyDirection > 0) ? flyVelocity : -flyVelocity; } _rigidbody.AddForce(transform.up * flyVel * Time.deltaTime, ForceMode.VelocityChange); } #endregion
The script is currently really basic, but I hope it will help you a bit. Of corse you will need to handle your animations correct and maybe block some actions while flying.
Cheers! sickscore
|
|
|
Post by shadex on Feb 17, 2017 17:10:45 GMT
Hey, I'm currently working on this for a project. Here are some snippets and steps to reproduce. vThirdPersonInput.cs- Create 3 new GenericInput's: public GenericInput flyInput = new GenericInput("X", "X", "X"); public GenericInput flyUpInput = new GenericInput("Space", "X", "X"); public GenericInput flyDownInput = new GenericInput("C", "X", "X"); - Create a method for handling your input: protected virtual void FlyInput () { if (flyInput.GetButtonDown ()) cc.Fly ();
if (flyUpInput.GetButton ()) cc.flyDirection = 1; // raise else if (flyDownInput.GetButton ()) cc.flyDirection = -1; // sink else cc.flyDirection = 0; // reset } vThirdPersonController.cs- Add Fly method public virtual void Fly () { if (animator.IsInTransition (0)) return;
// know if has enough stamina to make this action bool staminaConditions = currentStamina > flyStamina;
// conditions to do this action bool flyConditions = !isCrouching && !actions && staminaConditions;
// return if flyConditions is false if (!flyConditions) return;
// trigger fly behaviour isFlying = true; isJumping = false;
// trigger fly animations if (speed < 0.1f) animator.CrossFadeInFixedTime ("Fly", 0.1f); else animator.CrossFadeInFixedTime ("FlyMove", 0.05f);
// reduce stamina ReduceStamina (flyStamina, false); currentStaminaRecoveryDelay = 1f; } vThirdPersonMotor.cs- Create variables: [Tooltip("Velocity applied to the rigidbody while mid-air")] public float flyVelocity = 20f; [HideInInspector] public int flyDirection = 0; // 1 = up | -1 = down - Add method to control the fly behaviour #region Fly Methods protected void ControlFlyBehaviour() { if (!isFlying) return; _rigidbody.useGravity = false;
// interrupt flying when out of stamina or grounded/crash-landed :) if (currentStamina <= 0f || isGrounded) { isFlying = false; return; }
// raise / sink while flying // NOTE: Just for testing, not finished ;) float flyVel = 0f; if (flyDirection != 0) { flyVel = (flyDirection > 0) ? flyVelocity : -flyVelocity; } _rigidbody.AddForce(transform.up * flyVel * Time.deltaTime, ForceMode.VelocityChange); } #endregion The script is currently really basic, but I hope it will help you a bit. Of corse you will need to handle your animations correct and maybe block some actions while flying. Cheers! sickscore May i request that you put this in the add-on section as well? perhaps with a little more detail on how you set it up? I think the community in general would want this. I know your not finished, but it is really cool feature.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 17, 2017 17:22:50 GMT
flying!!!!! sounds AWESOME!!!! Cant wait to try it out!!! :D
|
|
|
Post by sickscore on Feb 17, 2017 17:33:06 GMT
Alright guys, I will spend some hours over the weekend to complete the system...I will need it anyways for my project ;-)
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 17, 2017 17:36:02 GMT
All the addon people should just be a team, cause there is ALOT of people making AWESOME addons, and it's benefiting the community. sickscore, thank you for working on Flying system!!!!
|
|
|
Post by jrackley on Feb 18, 2017 1:35:05 GMT
This is definitely an awesome addition! Looking forward to trying it out for sure, and as shadex stated it would be great to add into the addons section as well.
|
|
|
Post by sickscore on Feb 18, 2017 21:32:38 GMT
Short update: The flight system is almost done I'm currently recording some mocap animations for you guys (fly in place / fly move) and doing some code cleanup. Detailed guide and unitypackage should be online tomorrow/monday in the AddOns section! Cheers! sickscore
|
|
|
Post by Legion on Feb 18, 2017 23:12:11 GMT
Short update: The flight system is almost done I'm currently recording some mocap animations for you guys (fly in place / fly move) and doing some code cleanup. Detailed guide and unitypackage should be online tomorrow/monday in the AddOns section! Cheers! sickscore I think I love you.
|
|
|
Post by sickscore on Feb 20, 2017 14:32:28 GMT
Just posted the system into the addons section. >CHECK IT OUT<@ Legion I hope I can meet your expectations
|
|