#no idea what to call it
1 messages · Page 1 of 1 (latest)
See when it tries to rotate towards the second enemy?
I want that to happen counter clockwise
yeah
not clockwise
from looking at mathf.smoothdampangle, I don't know why it isn't taking the closest path to the new rotation
I assume some stuff with angles that end up negative
I've had the same thing happen to me in animating
You try and animate something to spin 360 degrees
and it gets to 359
and goes all the way around
I swear I've solved this sort of problem in one of my projects years ago
have you ever tried quaternion.lerp?
I was using Lerp, but I couldn't deal with "elapsedTime" variables because I had to change the position every frame- so someone recommend smooth damp
It's trying to follow an object that is moving on the track
yes
yes
I would think that shouldn't be too huge of a problem
all you have to do is get the enemy's position and "lead" it by the velocity direction
It probably isn't, but I'm pretty daft rn so I couldn't figure out how to work around it
while simultaneously accounting for the turret's projectile speed (if you were even going to add that)
believe me, I barely know how to approach this problem
It'll just shoot whenever there is something in range, it doesn't care if it'll actually hit
or if it's anywhere near
which would be fine if it didn't take such a silly route to aim at it
I'm trying to prototype your current situation
float currentVelocity;
private void Update()
{
if (enemiesInLOS.Count != 0)
{
foreach (Transform rotatableTransform in mesh.rotatableTransforms)
{
Vector3 difference = rotateTarget - rotatableTransform.position;
float newAngle = Mathf.Atan2(-difference.y, -difference.x) * Mathf.Rad2Deg;
float angle = Mathf.SmoothDampAngle(rotatableTransform.localEulerAngles.z, newAngle, ref currentVelocity, .1f, Data.TurnSpeed);
rotatableTransform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
SetRotationTarget(Path.instance.GetFirstEnemy(enemiesInLOS).transform.position);
}
}
public void SetRotationTarget(Vector3 target)
{
rotateTarget = target;
}
Here is all related code
if it helps you do that
You can ignore all the "rotatableTransforms" stuff
@burnt iriswould you mind seeing how I made my turret?
I managed to get the turret to point towards the enemy without leading it
but what I wanted to showcase is that Quaternion.lerp seems to take the closest path to its target
Sure go for it