First Person Lance Movement?

I am making a jousting “simulator”.

Basically I am trying to figure out how to script the movement of lance. I’m not worried about any form of lunges or torso twisting by the player, just moving the lance in a manner which allows for the player to need skill to hit the practice targets.

I understand that the movement needs to be in a cone, so I need to just manipulate the tip of the lance. The player would be holding the lance in the lower right of the screen.

I’ve played around with trying to use some the vanilla scripts for key input (my preferred form of input for this task as mouse look has a different function) and then piecing together some custom scripts, but in every case the lance jets away from my player object. I cannot figure out how to anchor it to the player object (yes I have it as a child to the player).

Thanks for any help, I’m pretty stumped and can’t seem to find anything in a tutorial or the API that really jumps at me as a solution.

I would try to set the pivot point to the point where the player is holding the lance. And translate x/y mouse movements to clamped rotation on the lance, so that 0x/0y mouse position (middle of screen) would translate to the lance pointing straight forward, and +x would translate to the lance pointing left and so on.

Edit:

Sorry I re-read and saw that you preferred key inputs. Well then, you could maybe have

GameObject lance;

float h = 0.0f;
float v = 0.0f;

void Update(){
    If(Input.GetKeyDown(KeyCode.W)){
        v += somefloatvalue * Time.deltaTime;
    }
    
If(Input.GetKeyDown(KeyCode.S)){
        v -= somefloatvalue * Time.deltaTime;
    }

    h = Mathf.Clamp(h, minfloat, maxfloat);
    v = Mathf.Clamp(v, minfloat, maxfloat);

   lance.transform.Rotate(Quaternion.Euler(new Vector3(h, v, 0));
}

Obviously not completed script but you get the idea, hope that helps :smile:

Thanks much that pointed me in the right direction