I’m a beginner programmer slowly trying to understand Slerp & use it for a bullet-hell like game for enemy movement patterns. I want some enemies to loop in a circle 1 time then stop once the starting point. For my question though, I have 2 points:
Point A: (-3,0)
Point B (3,0)
My understanding is that, by default, Slerp kind of acts like a mathematical compass with the needle set at (0,0) and then drawing an arc between points A & B. In my example then, I would assume the height of my 180 degree arc would also be (0,3), but that is not the case as shown in the picture (the top red point is at (0,3). Clearly I am not understanding Slerp correctly. Any help?
Script:
public class SlerpCode : MonoBehaviour
{
[SerializeField] private Transform pointA;
[SerializeField] private Transform pointB;
[SerializeField] private Transform slerpObject;
Vector3.Slerp is intended to be used with direction vectors. I generally would therefore only use it with unit vectors. If you want a certain radius, I would consider that separately from the slerp. For example Slerp the direction from right to left (aka [1, 0] to [-1, 0]), and multiply the resulting vector by whatever radius you desire. You could even then apply some other function to the radius along the way and get all kinds of nice effects.
Slerp does not calculate the apex, it’s just spherical interpolation. Just see the formula over here. Note that the angle omega is simply the angle between the two direction vectors, as actually explained in the text. So it works pretty much the same as lerp, but with spherical factors instead of linear factors. That’s also why slerp would not work when your angle is exactly 180° as any kind of linear combination of your two vectors fall onto the same line. So it’s a degenerative case. So the two vectors have to be linearly independent.
So that’s how slerp “works”. Though I have to agree with @samana1407 that Slerp is not really a good way to make circular movements. It’s great for interpolating (unit) direction vectors from one direction to another and the angle is always less than 180°.
To actually move in circles you should define a center point and move the object around. There are many ways how this can be done. Though for bullethell games you usually have an additional requirement to have a lot of them follow the same path with equal spacing. So using procedural paths or splines may be necessary.
Thanks for the info. The math is a little beyond my current understanding but that is good to know that it doesn’t operate the way I thought it might.
Originally I was using transform.RotateAround to perform a loop, but I was having an issue with how to get it to stop looping since I only want the enemies to go in a circle once. I also took a brief glance at splines but I will definitely look a bit more into them. Thanks!
I must’ve watched that video over a dozen times haha. I did find that when I uploaded his demo package into unity & messed around with it that I could make a near perfect circle by offsetting the center by a small amount, say .01. I guess I am still confused how all this works. He says it interpolates as if it is around the circumference of a sphere which it what confuses me because that makes me think what I am trying to do should work. I know that there are probably simpler ways to do this, but now I am kinda set on at least understanding the basics of slerp, even if I’m not gonna use it haha