How do I check if an object is touching a tag?
I'm creating a third-person ledge climbing game (Like uncharted) but I need to check if my ledge detector is touching a game object with the tag Ledge. At default, a boolean called is climbing is false, but when the ledge detector touches the tag, it should swithc the navigation controls for a new set of climbing controls. Though at the moment, I haven't done the controls, I still need to get my ledge detector to check for tags.
//Movement
private Vector3 Velocity;
[SerializeField] private float Speed;
[SerializeField] private float JumpForce;
[SerializeField] private float Gravity;
public float SmoothTurnTime = 0.1f;
float TurnSmoothVelocity;
//Dynamic Climbing
private bool IsClimbing = false;
void Start()
{
}
void Update()
{
Movement();
Climbing();
}
private void Movement()
{
if (IsClimbing == false)
{
//Movement Script
float Horizontal = Input.GetAxisRaw("Horizontal");
float Vertical = Input.GetAxisRaw("Vertical");
Vector3 Direction = new Vector3(Horizontal, 0f, Vertical).normalized;
if (Direction.magnitude >= 0.1f)
{
float TargetAngle = Mathf.Atan2(Direction.x, Direction.z) * Mathf.Rad2Deg + Cam.eulerAngles.y;
float Angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, TargetAngle, ref TurnSmoothVelocity, SmoothTurnTime);
transform.rotation = Quaternion.Euler(0f, Angle, 0f);
Vector3 MoveDirection = Quaternion.Euler(0f, TargetAngle, 0f) * Vector3.forward;
Controller.Move(MoveDirection.normalized * Speed * Time.deltaTime);
}
//Sprinting Script
if (Input.GetKey(KeyCode.LeftShift))
{
Speed = 20f;
}
else
{
Speed = 10f;
}
//Gravity and Jumping Script
if (Controller.isGrounded)
{
Velocity.y = -1f;
if (Input.GetKeyDown(KeyCode.Space))
{
Velocity.y = JumpForce;
}
}
else
{
Velocity.y -= Gravity * -2f * Time.deltaTime;
}
Controller.Move(Velocity * Time.deltaTime);
}
}
private void Climbing()
{
if(IsClimbing == false)
{
------------------------------------
//!~-~!Need Help Here!~-~!\\
------------------------------------
}
}
If you have an alternative to using an object, please let me know.
Answer by TheIrishKraken · May 16 at 12:10 AM
You would set the ledge detector as a trigger and have the below function in its attached script.
Then tag your ledges as "Ledge" in the inspector.
Your answer
![](https://koobas.hobune.stream/wayback/20220613060523im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why can't you add editor scripts to GameObjects even if the tag is EditorOnly? 0 Answers
Is it possible to make a game object's mesh fit its collider? 1 Answer
How do i make precise colliders 0 Answers
How to access an inactive gameObject with tag 2 Answers
Detect Closest Game Object (with tag) To The Right Of Player Position (2D) 0 Answers