Help with rotating a spear

So instead of a cucumber I am using a spear however its normal orientation is so:
2019-12-17 (2)
Given its orientation I told it to rotate -52 degrees in the z direction leaving me with this:
2019-12-17 (3)

Now the problem comes when I tell it to move across the screen it starts correctly but then since I am telling it to move right it starts to move down to the right (since the right axis is down to the right).

So I have been trying to figure how to code in the correct movement

    [Range(0f, 10f)] [SerializeField] float spearSpeed = 1f;

    void Update()
    {
        var rotation = new Vector2(spearSpeed * Time.deltaTime, spearSpeed * Time.deltaTime);
        transform.Translate(Vector2.right * spearSpeed * Time.deltaTime);
        transform.Translate(Vector2.up * spearSpeed * Time.deltaTime);
    }

But I still get the same result of down to the right. I also tried an animation of telling the spear to rotate right at the beginning but then the spear will still fall down to the right instead of straight. Any ideas on how to get it to the spear to still move to the right without going down?

Alright minutes after posting this I went into the other discussion to closely read their problem and see if it was like mine. After looking at their code and problem I went and looked into the unity docs for Space.World. Doing this I saw that all I needed in my code was this Space.World.
Thus I typed this code into visual studio and everything works when orientated -52 degrees along the z axis:

    void Update()
    {
        transform.Translate(Vector2.right * Time.deltaTime * spearSpeed, Space.World);
        transform.RotateAround(transform.localPosition, Vector3.forward, spearSpeed * Time.deltaTime);
    }

Important to note there is a slight animation of rotating the spear over the course of slightly over .10 seconds. This just makes it look like the spear is upright when thrown and then goes spear head towards target after being thrown.

I was thinking you could also use forward, But the graphic is offset so that wouldn’t work. World space was the next option

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms