#no idea what to call it

1 messages · Page 1 of 1 (latest)

mental orchid
#

@burnt iriswhat exactly are you trying to achieve?

burnt iris
#

See when it tries to rotate towards the second enemy?

#

I want that to happen counter clockwise

mental orchid
#

yeah

burnt iris
#

not clockwise

mental orchid
#

from looking at mathf.smoothdampangle, I don't know why it isn't taking the closest path to the new rotation

burnt iris
#

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

mental orchid
#

I swear I've solved this sort of problem in one of my projects years ago

#

have you ever tried quaternion.lerp?

burnt iris
#

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

mental orchid
#

change the position as in...?

#

the target quaternion is different each frame?

burnt iris
#

It's trying to follow an object that is moving on the track

mental orchid
#

yes

burnt iris
#

so I need to change the end Goal of the lerp

#

every frame

mental orchid
#

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

burnt iris
#

It probably isn't, but I'm pretty daft rn so I couldn't figure out how to work around it

mental orchid
#

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

burnt iris
#

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

mental orchid
#

I'm trying to prototype your current situation

burnt iris
#
    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

mental orchid
#

@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

burnt iris
#

Sure go for it

mental orchid
#

uh

#

no vc