Substitute transform.rotation + slerp with transform.rotate and Vector3
I am using this method, to rotate ship towards target:
Vector3 pos = target.localPosition - transform.localPosition;
Quaternion rotation = Quaternion.LookRotation(pos);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, rotationalDamp * Time.deltaTime);
Yet for avoiding obstacles i cast numerous raycasts at different angles grouping them in directions[] array and use (for now simple method that doesn't average out the raycastOffset if there are 2 vectors at the same time, its not important now):
raycastOffset = Vector3.zero;
if(free_vectors==0)
raycastOffset = Vector3.left + Vector3.down;
else
{
if ((directions[1] == true)) raycastOffset += Vector3.left;
if ((directions[2] == true) && (directions[1] == false)) raycastOffset += Vector3.right;
if ((directions[2] == false) && (directions[1] == false)) raycastOffset += Vector3.left;
if ((directions[3] == true)) raycastOffset += Vector3.down;
if ((directions[4] == true) && (directions[3] == false)) raycastOffset += Vector3.up;
if ((directions[4] == false) && (directions[3] == false)) raycastOffset += Vector3.down;
}
[...]
prev_raycastOffset = (prev_raycastOffset * (1f - (rotate_change_lag * Time.deltaTime))) + (raycastOffset * (rotate_change_lag * Time.deltaTime));
transform.Rotate(prev_raycastOffset * rotate_speed * Time.deltaTime);
I interpolate the prev_raycastOffset, so that the ship has some drag (regulated by rotate_change_lag) while changing rotation to avoid obstacles. The problem is that when I look towards target with first function, it is clunky and I don't know how to merge these 2 methods (rotation+ Slerp) and transform.Rotate to include my rotation drag. Is it possible to convert the first function, so that it also uses transform.Rotate and an input Vector3 instead of transform.rotate? Then I could incorporate my one drag method for both types of rotations. Or maybe there is a better way?
I was thinking also about using Rigidbody and adding rotation force to achieve those rotations, which would give me much more natural rotation drag effect. It would be more professional, but I don't know even where to begin (not enough experience with it).
I spent already 1.5 day on trying to find any solution to this problem among questions in the past and I was open to solutions using any other method. Nothing. I am not surprised nobody even attempts to answer.
Your answer
Follow this Question
Related Questions
Change the Rotation X value without changing Y and Z 1 Answer
Move object towards a moving point C# 1 Answer
[SOLVED] How to LookRotation in only Y axis 0 Answers
Strange behavior on cube rotations 0 Answers
Some questions about rotate. 1 Answer