0% found this document useful (0 votes)
26 views3 pages

Experiment 3 Cu

The document analyzes 2D rigid body transformations in Unity, including translation, rotation, and scaling. It provides code examples to move, rotate, scale, and combine transformations of a 2D object. Questions at the end ask about 2D rigid bodies, the transformations, and the three I's of virtual reality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Experiment 3 Cu

The document analyzes 2D rigid body transformations in Unity, including translation, rotation, and scaling. It provides code examples to move, rotate, scale, and combine transformations of a 2D object. Questions at the end ask about 2D rigid bodies, the transformations, and the three I's of virtual reality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT - 03

Aim: Analyze the 2D rigid body transformation in Unity hub


1.1 CO Attained: CO1,CO2

1.2 Objective:
In this experiment, the 2D rigid body transformation is analyzed. A 2D rigid body
object transformation in Unity involves manipulating its position, rotation, and scale
while taking into account the physics simulation.

1.3 Resources: Unity Software

1.4 Description: Install the Unity's C# scripting language and execute the following codes
to analyize the rigid body transformation

Step 1: Translation: Translating or moving the object in 2D space.

using UnityEngine;

public class TranslationExample : MonoBehaviour


{
public float moveSpeed = 5f;

void Update()
{
// Move horizontally and vertically based on user input
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");

// Translate the object


Vector2 translation = new Vector2(horizontalInput, verticalInput) *
moveSpeed * Time.deltaTime;
transform.Translate(translation);
}
}

Step 2: Rotation : Rotating the object in 2D space.

using UnityEngine;

public class RotationExample : MonoBehaviour


{
public float rotationSpeed = 180f;

void Update()
{
// Rotate based on user input
float rotationInput = Input.GetAxis("Rotation");

// Rotate the object


float rotationAmount = rotationInput * rotationSpeed * Time.deltaTime;
transform.Rotate(Vector3.forward * rotationAmount);
}
}

Step 3 Scaling : Scaling the object in 2D space.

using UnityEngine;

public class ScalingExample : MonoBehaviour


{
public float scaleSpeed = 1.2f;

void Update()
{
// Scale based on user input
float scaleInput = Input.GetAxis("Scale");

// Scale the object


float scaleFactor = Mathf.Pow(scaleSpeed, scaleInput *
Time.deltaTime);
transform.localScale *= scaleFactor;
}
}

Step 4 Custom Transformations: Applying a combination of translation,


rotation, and scaling.

using UnityEngine;

public class CustomTransformationExample : MonoBehaviour


{
public float moveSpeed = 5f;
public float rotationSpeed = 180f;

void Update()
{
// Move horizontally based on user input
float horizontalInput = Input.GetAxis("Horizontal");
Vector2 translation = new Vector2(horizontalInput, 0f) * moveSpeed *
Time.deltaTime;
transform.Translate(translation);

// Rotate based on user input


float rotationInput = Input.GetAxis("Rotation");
float rotationAmount = rotationInput * rotationSpeed * Time.deltaTime;
transform.Rotate(Vector3.forward * rotationAmount);
}
}

Viva Questions:

Q. 1 Explain 2D rigid body?


Q. 2 Explain Translation, Rotation and Scaling?
Q. 3 What are 3 I’s in Virtual Reality?

You might also like