|
Post by archieandrews on Jul 4, 2018 20:54:55 GMT
Hi Is it possible to play specific audios when the character starts walking?
Example Scenario Character might start panting for breath, or simply whistle a tune while he is walking.
TY
|
|
|
Post by archieandrews on Jul 5, 2018 11:38:09 GMT
Is this possible ?? If so how TY
|
|
|
Post by Jader on Jul 5, 2018 12:18:48 GMT
Hi, try this:
using UnityEngine;
[RequireComponent(typeof(AudioSource))] public class example : MonoBehaviour {
public AudioClip IdleSound; public AudioClip WalkSound;
void Start(){ audio = GetComponent<AudioSource>(); }
void LateUpdate(){
if (Input.GetAxis("Vertical") != 0 && audio.clip != WalkSound){ audio.clip = WalkSound; audio.Play(); } if (Input.GetAxis("Vertical") == 0 && audio.clip != IdleSound){
audio.clip = IdleSound; audio.Play(); } } }
This script will make an abrupt switch. I don't know an easy way to create a transition between clips...
|
|
|
Post by archieandrews on Jul 5, 2018 12:34:18 GMT
HI Jader, thanks I was actually seeing if there was functionality within the Invector 3rd person functions direct to do this rather than additional coding but I get the principle of this. I guess you could also read the values of inputHorizontal & inputVertical directly from the 3rd person controller script (you can view this if Debug Window is enabled). Crossfading Audio needs little extra code but that's not critical for me.
Cheers A
|
|
|
Post by Jader on Jul 5, 2018 13:12:15 GMT
You can also get information from the animator to adapt the breath according to the current state. There are some parameters in the invector scripts that can serve this, but I can not search on them now... A good idea would be to use the percentage of stamina as a parameter
|
|
|
Post by archieandrews on Jul 5, 2018 13:13:54 GMT
This reads the Vertical and Horizontal Inputs from 3rd person controller
using System.Collections; using System.Collections.Generic; using UnityEngine; using Invector.vCharacterController;
public class CheckInput : MonoBehaviour {
// public vThirdPersonInput vController; public vThirdPersonController vController; // Use this for initialization void Start () { vController = GameObject.Find("vThirdPersonBasic").GetComponent<vThirdPersonController>();
}
// Update is called once per frame void Update() { Debug.Log(vController.input.x); Debug.Log(vController.input.y); } }
|
|
|
Post by archieandrews on Jul 5, 2018 13:20:08 GMT
You can also get information from the animator to adapt the breath according to the current state. There are some parameters in the invector scripts that can serve this, but I can not search on them now... A good idea would be to use the percentage of stamina as a parameter Thanks again. I'm a 3D modeller and visual artist with a long term background in tech engineering, but not a a Unity dev so I'm limping to understand some of this product.
I really think Invector should invest more time and approach to their documentation for non dev types. Its not rocket science to understand but it is missing the basic fundamentals of documentation. Basically its too brief and makes assumptions all end users are Unity devs.
|
|
|
Post by Jader on Jul 5, 2018 13:25:59 GMT
Input changed, does not necessarily mean that the character is walking.
Example, if you are facing a wall, even by input vertical 1, it will not walk. So I think it's best to use the states of the animator, it will ensure that the player is actually performing the movement.
|
|
|
Post by Legion on Jul 5, 2018 13:59:20 GMT
|
|
|
Post by Jader on Jul 5, 2018 14:23:57 GMT
Animation Events is great too. But as it is executed with each loop of the animation, be careful doing the check if the audio already playing, as in the example that I gave with the input...
|
|