Boosted snowboarder seems to rotate

When I do the boost, either he gets narrower due to approaching the speed of light, or the 2D snowboarder image is rotating slightly sideways. Since he stays that way when he returns to normal speed, I am betting it is due to rotation for some reason.

Not sure how that happens though, since the only thing being changed is the speed value for SurfaceEffector.

My code matches what was in the lesson, except for using 15.0f as my base speed.

Any ideas?

Hi Ivskiprof,

Could you please share screenshots of what you see in Unity? I’m also interested in the player’s transform when he gets narrower.

Nina,

Sorry I couldn’t reply to my original post before it got closed.

I captured a video that shows the issue, but I don’t see how I can attach it here. It only accepts image files. Can you suggest how I can share this to you?

I noticed that it is actually distorting somewhat during the normal movement, but it does it more when I press the Up Arrow cursor key. They video makes it more obvious than a still image would.

Mike

Hi Ivskiprof,

Welcome back. I re-opened your thread and moved your post here. :slight_smile:

Regarding your video, if it is very large, you could upload it to Youtube and share a link here. Other students upload their videos to, for example, OneDrive and share a link.

Thanks Nina. The problem was that my old work email was where notices were being sent. I am working with the support group to get that changed. That is why I missed your replies earlier.

I had OneDrive, but it wasn’t set up for my account, so it is syncing now. Once that is done I will put the link in for the MP4 file.

Here is the link: https://1drv.ms/v/s!Ar9oS0hb0FiFh_RqVO6nV5dn-eLP5g?e=o86Gww

Thank you for the video. That was helpful. Barry looks as if he rotates around the x- and y-axis. In our game, he is supposed to rotate around his z-axis only.

Click on the Barry game object, then go to his Rigidbody2D component. Under "Constraints > “Freeze Rotation”, make sure x and y are ticked.

Did this fix it?


See also:

When I do that he still appears to rotate.

As you can also see in the video he goes fairly deep into the snow when he drops onto it or if he does a jump. Would like to understand that as well.

BTW - My guy is named Shawn, because I was a big Shawn White fan. :slight_smile:

Here is how it looks in the Inspector:

Try to set “Interpolate” value in the Rigidbody2D component to “Interpolate”. Maybe that’ll fix the issue.

Don’t freeze the z-axis. That’s the axis Shawn is supposed to rotate around.

Apart from this, I do not see any potential issue in your screenshots. If Shawn still rotates around the wrong axes, I’m wondering if there might be an issue in your code. Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

Which version of Unity do you use?

It acts the same when I set it to Interpolate.

I am using 2021.3.0f1, so I am on the initial LTS version now.

Here is the code for PlayerController:

public class PlayerController : MonoBehaviour
{
    [SerializeField]
    float torqueAmount = 10.0f;
	[SerializeField]
	float boostSpeed = 30.0f;
	[SerializeField]
	float baseSpeed = 15.0f;

	Rigidbody2D rb2d;
    SurfaceEffector2D surfaceEffector2D;

    /***
    *       Start is called before the first frame update
    ***/
    void Start()
    {
        rb2d = GetComponent<Rigidbody2D>();
        surfaceEffector2D = FindObjectOfType<SurfaceEffector2D>();
		surfaceEffector2D.speed = baseSpeed;
    }   // Start()

    /***
    *       Update is called once per frame
    ***/
    void Update()
	{
		RotatePlayer();
		RespondToBoost();
	}   // Update()

	void RespondToBoost()
	{
		if (Input.GetKey(KeyCode.UpArrow))
		{
			surfaceEffector2D.speed = boostSpeed;
		}	// if
		else
		{
			surfaceEffector2D.speed = baseSpeed;
		}	// else
	}   // RespondToBoost()

	void RotatePlayer()
	{
		if (Input.GetKey(KeyCode.LeftArrow))
		{
			rb2d.AddTorque(torqueAmount);
		}   // if
		else if (Input.GetKey(KeyCode.RightArrow))
		{
			rb2d.AddTorque(-torqueAmount);
		}   // else-if
		else
		{
			rb2d.AddTorque(0);
		}   // else
	}   // RotatePlayer()
}   // class PlayerController

Unfortunately, I cannot spot any issue in your code. I rewatched the video and noticed that other sprites rotate as well. I’m not sure if that’s also the case for the snow.

Could it be that the camera rotates? Check its Inspector when Shawn gets distorted. Is the Camera Mode set to “Orthographic” in the Camera component?

The camera is set that way already.

I was just doing the lesson on sound and noticed that with the Z rotation disabled I couldn’t get him to crash, so I restored that back to the earlier setting.

Here is the camera settings:

Is there a reason why your camera is rotated around the y-axis? An orthographic camera is usually not supposed to be rotated.

That is a good question. It was not on purpose and when I try to change it in the editor it goes back to the same setting.

That’s odd. The game is not running when you try that, is it?

Is there something else in your game that might be affecting the values of the camera? An animation or a cinemachine component?

Also check if the camera has got a Collider2D component attached. If it does, remove that component.

No there is no Collider2D attached to it.

I can provide a link to a ZIP of the entire project if you wish.

Not sure what’s going on, but watching the video, it isn’t just the snowboarder rotating. The whole scene shifts. Noticeable by looking at the trees. So possibly something wrong with the camera.
Just a little observational assistance in hopes it helps you detect the issue.

You are right, @ChibelD. That’s very likely the problem. Ivskiprof shared a screenshot.

image

From what I understood, he set the value to 0 while the game was not running but when he started the game, the camera suddenly rotated. We are now trying to figure out why that happens. Interestingly, only the y-axis is affected.

@lvskiprof, could you please share a screenshot of your CinemachineVirtualCamera component(s)? The player game object or another game object are not assigned to “Look At”, are they?

I see what you mean by the trees. When I put the Game view so it showed the whole window it was more obvious.

I do have Shawn (the player) game object set for Look At:

Your cameras is rotated by 22? Maybe that is causing it? As @Nina has mentioned above.
What you’ll want to do select both the Main Camera, and your CM vcam1(hold control and click on each one in the heirarchy) as you can’t change the transform separately. You’ll then go and change the rotation to 0.
You can’t change the Main Camera while it is linked with the CM vcam1

1 Like

Privacy & Terms