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

Gamedev Project 1

This document contains code for a 3D car game created in Unity. The code allows a capsule rigidbody to move horizontally and vertically based on input and jump if grounded. Screenshots of the game are also included.

Uploaded by

Pratham singh
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)
13 views

Gamedev Project 1

This document contains code for a 3D car game created in Unity. The code allows a capsule rigidbody to move horizontally and vertically based on input and jump if grounded. Screenshots of the game are also included.

Uploaded by

Pratham singh
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

BYOD Practical

Subject : Game Development Section : K21FR


Name : Pratham Singh Registration no. : 121116272

CarGame 3D

Game code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour


{
Rigidbody capsule;
[SerializeField] float movementspeed=5f;
[SerializeField] float jumpForce=5f;
[SerializeField] Transform groundCheck;
[SerializeField] LayerMask ground;
// Start is called before the first frame update
void Start()
{
capsule=GetComponent<Rigidbody>();
// Debug.Log("Hello from Start!");
}

// Update is called once per frame


void Update()
{
float horizontalInput=Input.GetAxis("Horizontal");
float verticalInput=Input.GetAxis("Vertical");

capsule.velocity=new
Vector3(horizontalInput*movementspeed,capsule.velocity.y,verticalInput*movementspeed);
// Debug.Log("Hello from Update!");
if(Input.GetButtonDown("Jump") && IsGrounded()){
capsule.velocity=new Vector3(capsule.velocity.x,jumpForce,capsule.velocity.z);
}
bool IsGrounded(){
return Physics.CheckSphere(groundCheck.position,.1f,ground);
}
/*--> ye code bhi thik hai but perfect nhi smjhe bhai <--
// if(Input.GetKey("up")){
// capsule.velocity=new Vector3(0,0,5);
// }
// if(Input.GetKey("right")){
// capsule.velocity=new Vector3(5,0,0);
// }
// if(Input.GetKey("down")){
// capsule.velocity=new Vector3(0,0,-5);
// }
// if(Input.GetKey("left")){
// capsule.velocity=new Vector3(-5,0,0);
// }
*/

Game Screenshots :

You might also like