- Home /
Different sound the higher I go on the surface
I want when walking around with a character, footsteps or me colliding with the surface to sound differently, the higher/lower I go.
Sounds should preferably be not random, but a higher tune for the higher I am etc. or at least similar highs should have similar sounds (even if sounds are random).
Here is an example of a surface. P.S. I am desperate.
Is there a reason why you don't just set the pitch to something proportional to your character's vertical component?
Assu$$anonymous$$g your footstep sound effect is using an AudioSource, there is a pitch
property you can use.
I don't remember the know the default value for`pitch` with AudioSource components, but you'd so something like:
audioSource.pitch = DEFAULT_PITCH + HEIGHT_TO_PITCH_RATIO * (DEFAULT_HEIGHT - this.transform.position.y);
where the values in caps are parameters you will choose based on your situation.
Thank you. Let me try. I need just to figure out how scripting works in unity haha I am a total beginner
Answer by TreyH · Apr 16, 2018 at 07:26 PM
This was discussed in the comments:
using UnityEngine;
// Attach this to something in your scene, preferably the player object
public class PitchAdjustment : MonoBehaviour
{
// The AudioSource we're adjusting and the object whose height will adjust this pitch
//
// These MUST be assigned in the inspector.
//
public AudioSource audioSource;
public Transform targetTransform;
// You will want to tune this as needed
public float pitchToHeightRatio = 10;
// Base values
private float defaultPitch;
public float defaultHeight;
// Initialize our values with those components
void Awake()
{
this.defaultPitch = this.audioSource.pitch;
this.defaultHeight = this.targetTransform.position.y;
}
void Update()
{
// Adjust the pitch each frame
this.audioSource.pitch = this.defaultPitch + this.pitchToHeightRatio * (this.defaultHeight - this.targetTransform.position.y);
}
}
medianHight was missing, but even when adding public float medianHeight
, still says script can not be loaded
Updated for default height, what error is it giving you? Did you name the script correctly?
Your answer
Follow this Question
Related Questions
help with multiple sounds 0 Answers
Audio doesn't play 1 Answer
NGUI Volume And Quality Controle With Sliders Not working 1 Answer
Play from a variety of sounds? 1 Answer
multiple sounds, sound....sucky 0 Answers