0% found this document useful (0 votes)
4 views

GPP 6

MU GP P6

Uploaded by

rugvedshetge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

GPP 6

MU GP P6

Uploaded by

rugvedshetge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

T110 Rugved Shetge

Practical No. 6

Aim : Create Camera Shake Effect in Unity

Description :

Unity :
Unity is a versatile and widely-adopted game development engine that
empowers developers to create interactive experiences across multiple
platforms, including 2D and 3D games, augmented reality (AR), virtual reality
(VR), and other real-time applications. Renowned for its flexibility, user-friendly
interface, and robust feature set, Unity serves as a go-to tool for both indie
developers and large-scale studios.

Camera Shake Effect:


The camera shake effect in Unity is a visual technique used to simulate the
impact or intensity of certain events, such as collisions, explosions, or powerful
actions. By temporarily displacing the camera's position or rotation, it creates a
sense of motion and intensity, making events in the game feel more impactful.
This effect is typically triggered during significant moments in gameplay, such
as when a character collides with an object or when a powerful attack lands.

Circle Collider 2D:


A Circle Collider 2D in Unity is a component that defines a circular area of
collision for a 2D object. It's commonly used for objects that have a round
shape or for characters and objects where a circular collision area is sufficient.
The Circle Collider 2D detects overlaps or collisions with other colliders in the
game world, allowing you to define how objects interact with each other
physically.
T110 Rugved Shetge

Rigidbody 2D: Rigidbody 2D is a component in Unity that adds physics-based


movement to a 2D object. When an object has a Rigidbody 2D component, it
becomes influenced by forces such as gravity and collisions, allowing it to move
and react naturally within the game world. The Rigidbody 2D is essential for
creating dynamic objects that respond to player input or environmental factors,
making it a crucial part of any physics-based game.

Box Collider 2D: A Box Collider 2D in Unity is a rectangular collider used to


define the collision area for a 2D object. It is ideal for objects with a box-like
shape, such as platforms, walls, or crates. The Box Collider 2D detects collisions
with other colliders and is often paired with Rigidbody 2D to create objects that
can interact physically with their environment.
T110 Rugved Shetge

Code :
using UnityEngine;

public class CameraShake : MonoBehaviour


{
public Transform cameraTransform;
private Vector3 originalPosition;
public float shakeFrequency = 0.1f;
public float shakeDuration = 0.5f;

private float shakeTimeRemaining;

void Start()
{
if (cameraTransform == null)
{
cameraTransform = Camera.main.transform;
}
originalPosition = cameraTransform.position;
}

void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
ShakeCamera();
T110 Rugved Shetge

if (shakeTimeRemaining > 0)
{
cameraTransform.position = originalPosition + Random.insideUnitSphere
* shakeFrequency;
shakeTimeRemaining -= Time.deltaTime;
}
else
{
cameraTransform.position = originalPosition;
}
}

public void ShakeCamera()


{
shakeTimeRemaining = shakeDuration;
}
}
T110 Rugved Shetge

Output :

You might also like