Git Product home page Git Product logo

rollaball's Introduction

Exp.2 RollaBall

Aim:

To Roll a Ball using C# program in unity .

Algorithm:

  1. File -> Scene -> Select the scene -> Save as-> New folder(Scenes)-> File name (MiniGame)

  2. Heirarchy -> 3D Object-> Plane [ Right side-> Inspector-> Change the name of plane (Name: Ground) Transform -> Reset Edit -> FrameSelected ]

  3. Scale the ground by giving the scaling value as x=4 y=1 z=4

  4. Heirarchy -> 3D Object-> Sphere [ Right side-> Inspector-> Change the name of plane (Name: Player) Transform -> Reset Edit -> FrameSelected Transform -> Position -> y=0.5]

  5. Hierarchy -> DirectionalLight [ Inspector -> Change the color to white (255,255,255)]

  6. Create a folder in project and name as Materials [Material folder -> Create -> Material (Name: Background) Inspector ->Surface Inputs ->BaseMAp (Choose the color) Metallic map-> 0 Smoothness -> 0.25 Drag the Background to the plane and release the mouse

Material folder -> Create -> Material (Name: Sphere) Inspector ->Surface Inputs ->BaseMAp (Choose the color) Metallic map-> 0 Smoothness -> 0.75 Drag the Sphere material to the ball and release the mouse

  1. Hierarchy -> Player-> Inspector ->Add component-> Rigidbody

  2. Create a new script -> Create a folder in project (Name: Scripts) Hierarchy -> Player -> Inspector-> AddComponent-> NewScripts-> PlayerController( Click create and Add) Copy the PlayerController and drag to Script folder Double click the PlayerController file and type the coding

Program:

### Developed by: Srijith R
### Register Number: 212221240054
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{
    public float XForce = 5.0f;
    public float ZForce = 5.0f;
    public float YForce = 200f;

        // Start is called before the first frame update
    void Start()
    {

    }
    // Update is called once per frame
    void Update()
    {
        float x = 0.0f;
        if(Input.GetKey(KeyCode.A))
        {
            x = x - XForce;
        }
        if (Input.GetKey(KeyCode.D))
        {
            x = x - XForce;
        }
        float z=0.0f;
        if (Input.GetKey(KeyCode.W))
        {
            z= z +ZForce;
        }
        if (Input.GetKey(KeyCode.S))
        {
            z = z - ZForce;
        }
        float y= 0.0f;
        if (Input.GetKeyDown(KeyCode.Space))
        {
            y = YForce;
        }
        GetComponent<Rigidbody>().AddForce(x, y, z);
    }
}

Output:

output

output

Result:

Thus, The 3D application for Roll the Ball objects in unity is developed successfully.

rollaball's People

Contributors

archanasharikalharinarayanan avatar srijithmass avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.