- Home /
This question was
closed Dec 10, 2018 at 07:53 AM by
hexagonius.
Question by
TheCreatorultim · Dec 10, 2018 at 12:25 AM ·
c#rotationchangelookat
Change output rotation of this Lookat script?
{
Quaternion _lookRotation =
Quaternion.LookRotation((to - transform.position).normalized);
transform.rotation =
Quaternion.Lerp(Quaternion.Euler(transform.rotation.x, transform.rotation.y, transform.rotation.z + 90), _lookRotation, Time.deltaTime * turn_speed);
}
This will always turn from the Z side, though i'd like to have it turn from the X side? how could i change it?
full code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rotate : MonoBehaviour {
public float turn_speed;
public float Find_radius;
public string TagToSearchFor;
[Header ("Front, Left, Back, Top, Bottom")]
[Tooltip("Z points to front")]
public string Direction;
private Collider[] all_found;
private Transform Target;
private void check() {
all_found = Physics.OverlapSphere(gameObject.transform.position, Find_radius);
if(all_found.Length != 0)
{
foreach(Collider col in all_found)
{
if(col.tag == TagToSearchFor)
{
Target = col.gameObject.transform;
break;
}
}
}
}
protected void rotateTowards(Vector3 to)
{
Quaternion _lookRotation =
Quaternion.LookRotation((to - transform.position).normalized);
transform.rotation =
Quaternion.Lerp(Quaternion.Euler(transform.rotation.x, transform.rotation.y, transform.rotation.z + 90), _lookRotation, Time.deltaTime * turn_speed);
}
private void Update()
{
try
{
rotateTowards(Target.position);
}
catch
{
check();
}
}
}
Comment
Follow this Question
Related Questions
Change output rotation of this Lookat script? 2 Answers
Flip over an object (smooth transition) 3 Answers
Make object only rotate in 90 degree increments 0 Answers
Bullet not moving towards player 3 Answers
slowly rotate a object *need quick fix* 0 Answers