# How to wrap around the z axis and calculate x and y components?

Long story short, I’m trying to apply thrust to my gameobject/sprite so that it moves in the direction it is pointing at (instead of just moving right when pressing space and tilting left and right when pressing left and right arrow keys).

From a given instruction pdf it said to use an EulerAngles field with a Vector3 and (#1) rotate around the z axis, (#2) convert the angle to radians using Mathf Deg2Rad and (#3) calculate the appropriate values of the x and y components using Mathf Cos and Mathf Sin methods.

I’ve done (#2) (correctly converting degrees to radians) but I have no idea how to do (#1) and (#3).

I’ve also looked at the scripting reference but I’m not sure how to apply it in this context.

``````using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UIElements;
///<summary>
/// This is a ship script.
///</summary>
public class Ship : MonoBehaviour
{
const float rotateDegreesPerSecond = 50;

#region
private Rigidbody2D ShipRigidbody2D;
#endregion
#region
private CircleCollider2D Col;
#endregion
// saved for efficiency
float colliderHalfWidth;
float colliderHalfHeight;
public Vector3 eulerAngles;
public float deg = 30.0F;
void Start()
{
ShipRigidbody2D = GetComponent<Rigidbody2D>();

Col = gameObject.GetComponent<CircleCollider2D>();
Debug.Log(deg + " degrees are equal to " + rad + " radians.");
}
#region
Vector2 vel = new Vector2(1, 0);
#endregion
const float ThrustForce = 5;
void FixedUpdate()
{
float space = Input.GetAxis("Thrust");
space *= ThrustForce;
vel.x = space;
ShipRigidbody2D.velocity = vel;
}
// Makes object temporarily ivisible after it leaves scene
void OnBecameInvisible()
{

}
void Update()
{
ClampInScreen();
float rotationInput = Input.GetAxis("Rotate");

// calculate rotation amount and apply rotation

float rotationAmount = rotateDegreesPerSecond * Time.deltaTime;
if (rotationInput < 0)
{
rotationAmount *= -1;
}
transform.Rotate(Vector3.forward, rotationAmount);
}
void ClampInScreen()
{
// clamp/wrap screen as necessary
Vector2 position = transform.position;
if (position.x - colliderHalfWidth < ScreenUtils.ScreenLeft)
{
position.x = ScreenUtils.ScreenLeft + colliderHalfWidth;
}
else if (position.x + colliderHalfWidth > ScreenUtils.ScreenRight)
{
position.x = ScreenUtils.ScreenRight - colliderHalfWidth;
position.x *= -1;
}
if (position.y + colliderHalfHeight > ScreenUtils.ScreenTop)
{
position.y = ScreenUtils.ScreenTop - colliderHalfHeight;
}
else if (position.y - colliderHalfHeight < ScreenUtils.ScreenBottom)
{
position.y = ScreenUtils.ScreenBottom + colliderHalfHeight;
position.y *= -1;
}
transform.position = position;
float rotationInput = Input.GetAxis("Rotate");
}

}
``````

your object’s transform has standard vectors called ‘forward’, ‘up’, and ‘left’. Use those, no Eulers involved

sorry, how do I use those in c#? And where do I type them to begin with? this code has a ton of clutter and I’m losing track at this point

So I’m assuming that I can wrap around the z axis without using eulers