You are on page 1of 7

Parijat Niyogy Lab Assessment 3 19BCE0696

Aim:
1. How to call the various functions and libraries, which are pre-build in unity? Basic
implement.
2. Environment Design and world building (Background Design, terrain painting)

Procedure:
1.
• Create a new 3d project
• For a player movement script, the code is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour


{
// VARIABLES
[SerializeField] private float moveSpeed;
[SerializeField] private float walkSpeed;
[SerializeField] private float runSpeed;

private Vector3 moveDirection;


private Vector3 velocity;

[SerializeField] private bool isGrounded;


[SerializeField] private float groundCheckDistance;
[SerializeField] private float gravity;
[SerializeField] private LayerMask groundMask;

[SerializeField] private float jumpHeight;

// REFERENCES
private CharacterController controller;

private void Start(){


controller = GetComponent<CharacterController>();
}

private void Update()


{
Move();
}

private void Move()


Parijat Niyogy Lab Assessment 3 19BCE0696

{
isGrounded = Physics.CheckSphere(transform.position,
groundCheckDistance, groundMask);

if(isGrounded && velocity.y < 0)


{
velocity.y = -2f;
// Simply setting it to a small negative value in order to stay
grounded
}

float moveZ = Input.GetAxis("Vertical");

moveDirection = new Vector3(0,0,moveZ);

if(isGrounded)
{
if (moveDirection != Vector3.zero &&
!Input.GetKey(KeyCode.LeftShift) )
{
// Walk
Walk();
}
else if(moveDirection != Vector3.zero &&
Input.GetKey(KeyCode.LeftShift) )
{
// Run
Run();
}
else if(moveDirection == Vector3.zero)
{
// Idle
Idle();
}

moveDirection *= moveSpeed;

if(Input.GetKeyDown(KeyCode.Space))
{
Jump();
}
}

controller.Move(moveDirection * Time.deltaTime);

velocity.y += gravity * Time.deltaTime;

controller.Move(velocity * Time.deltaTime);
Parijat Niyogy Lab Assessment 3 19BCE0696

private void Idle(){

private void Walk(){


moveSpeed = walkSpeed;
}

private void Run(){


moveSpeed = runSpeed;
}

private void Jump(){


velocity.y = Mathf.Sqrt(jumpHeight * -2 * gravity);
}

}
Parijat Niyogy Lab Assessment 3 19BCE0696

Testing the player walk and run functions


Parijat Niyogy Lab Assessment 3 19BCE0696

Testing the jump function

• In the Move() function, the ‘transform’ library is called.


• ‘transform.TransformDirection(vector3)’ is used to change the direction to the direction of the
vector.
Parijat Niyogy Lab Assessment 3 19BCE0696

2.
• Create a 3D project.
• Import assets for grass, trees and terrain materials.
• In the Project Hierarchy, create a terrain.
• In the Inspector section, click on paint terrain.
• Click on ‘Raise and Lower Terrain’ and then select the various brushes to edit the
terrain, by raising and lowering portions of it.
• Change the brush size and opacity accordingly.
• Select ‘Paint Texture’ and import the layers by pressing ‘add layer’
• After this paint the terrain accordingly
• Create pathways with different terrains.
• Add trees by selecting the ‘Paint Trees’ option.
• Import the assets and add different trees.
• Add a suitable sky of choice
Parijat Niyogy Lab Assessment 3 19BCE0696

Result:
Therefore, the Libraries and Functions prebuilt in Unity has been utilized as well as the
environment design and painting of textures have been implemented.

Conclusion:
Built-in functions are important throughout game development. Game Engines
provide the use of several built-in functions and libraries to make game development a
smooth process. They are also fine tuned to consume the least execution time possible and
occupy very less space. There are optimized and better built than user defined functions.
Environment design is vital to any dimensional game of any genre. This helps the
player have an interesting experience and helps the players throughout the game.

You might also like