Help on lerping well really a kick in the right direction really

Hello all,

I have a fairly simple PlayerContoller at the moment which just happens to be for a space type game.
It currently moves my ship with pitch, yaw and roll. When a yaw I have it banking(angling) my ship in the proper direction, but I would like it to RInterp in that direction instead of teleporting. Can anyone please let me know where and what I need to do with it, or even just a helpful (here it comes) kick in the right direction to the documentation?

Sorry Ninjachimp I pasted a code block :frowning: but it is not broken and self contained.

public class PlayerController1 : MonoBehaviour {

public float xShip;
public float yShip;
public float zShip;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void FixedUpdate () {
xShip = Input.GetAxis(“Horizontal”) * Time.deltaTime * 25.0f;
yShip = Input.GetAxis(“Vertical”) * Time.deltaTime * 25.0f;
zShip = Input.GetAxis(“Roll”) * Time.deltaTime * 25.0f;

    transform.Rotate(0, xShip, 0);
    RotateChild();
    transform.Rotate(yShip, 0, 0);
    transform.Rotate(0, 0, zShip);
}
void RotateChild(){
   
    if (xShip > 0){
        foreach (Transform child in transform)
            child.localRotation = Quaternion.AngleAxis(-30, Vector3.forward);
    } else if (xShip < 0)
    {
        foreach (Transform child in transform)
            child.localRotation = Quaternion.AngleAxis(30, Vector3.forward);
    } else if(xShip == 0)
    {
        foreach (Transform child in transform)
            child.localRotation = Quaternion.AngleAxis(0, Vector3.forward);
    }
}

}

I am guessing you mean you want to use Vector3.Lerp?

https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html

I use it a lot for some of my games. Apart from that, apologies, I got really confused with ‘pitch’ and ‘yaw’? Hopefully Vector3.Lerp is what you need? :confused:

I am heading out for the night so I will look into this in the morning. Pitch is the Up/Down (vertical axis) movement of an object like an airplane, Yaw is the Right/Left (horizontal axis) movement.

Actually, you probably don’t need Lerp at all. I’m guessing this is a 2D game, looking from the top?

How about transform.Translate? That will probably help you with how you want to move the plane.

Its a 3D game her is a video of what it is doing, again its not broken I just want to make the banking rotations fluid with a lerp or rinterp.

PS I removed my ship meshes and added my own Enterprise D for the video.

OK! Now I know what you mean!

Vector3.Lerp can definitely help you, Lerp those rotations instead.

Try using quaternions for rotations like that, Vector3 isn’t ideal to handle complex rotations. What may be the problem here is that you are adressing the new quat to the localrotation, try adding it to the actual rotation instead ( “+=” instead of “=”) let me know if you manage to fix that, otherwise I can take a further look on that. This video helped me a lot, you may benefit from watching it too:

maybe also try Vector3.Slerp? (as opposed to Lerp, I’m causing much confusion now :D)

Hey Guys sorry I didn’t post this yesterday but I figured it out. Was rather simple but not sure it is the right way. :slight_smile:

This the code I implemented:

// Update is called once per frame
void Update () {
float v = Input.GetAxis(“Vertical”);
float h =+ Input.GetAxis(“Horizontal”);

    transform.localRotation = Quaternion.AngleAxis(-h * 45, Vector3.forward);
}

What I ended up doing is creating an empty object and added my meshes to it (they are in multiple parts) then added a banking script above to the banking object.

Here is a quick video of the final product. Its not perfect but I can dig into that another day.

1 Like

Thanks for that video most of it I knew but was a good refresher and I will go through all his others now :slight_smile:

1 Like

I really liked that video :smiley: he is a good teacher.
Im glad to know that you solved that problem, congratulations!!

By the way, your game is looking very good :open_mouth: looking forward to see more of it