Top Banner
Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta Tri Anggraeni, S.Kom., M.Sc.
20

Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

May 31, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Pertemuan 5Roll a Ball (Part 4)

Mata Kuliah Logika GameProgram Studi Teknologi PermainanSekolah Tinggi Multi Media YogyakartaTri Anggraeni, S.Kom., M.Sc.

Page 2: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Menampilkan pesan ketika semua cube telah diambil• Di Hierarchy Unity:

Klik

Rename jadi Win Text

Page 3: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

• Set:

• Ubah warna text, misal menjadi putih (cek slide 25 jika lupa caranya).

• Ubah text menjadi:

• Ubah font size menjadi 24.• Ubah Alignment menjadi center & middle:

Page 4: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Di skrip PlayerController:

• Tambahkan: public Text winText; • Di function Start, tambahkan:

winText.text = "";

• Di function SetCountText() tambahkan:if (count >= 12) {

winText.text = "You Win!";}

Page 5: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Di Unity: klik objek Player

• Drag objek Win Text ke

• Sehingga:

• Save. Klik Play . Jalankan sphere Player & gerakkan ke cube.

Page 6: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Building game (Presenting the game to the player)

• Save scene. Klik menu File, Build Settings.

Klik

/Drag

Page 7: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Klik

Page 8: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Buat folder Build di root

Page 9: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Buka folder Build, ketikkan nama game

Klik

Page 10: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Pertemuan 5Runner Game Sederhana

Mata Kuliah Logika GameProgram Studi Teknologi PermainanSekolah Tinggi Multi Media YogyakartaTri Anggraeni, S.Kom., M.Sc.

Referensi: mammothinteractive.com

Page 11: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Runner Game Sederhana

• Untuk membuat endless run game.• Yang terbaru buatan mahasiswa skripsi TP: Game

Care in the Space (buatan Dhia Irfan).

Page 12: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Menggerakkan Player• Klik Player, Add Component, New

Script.

• Diinginkan: cube Player bergerak ke atas ketika pemain menekan keyboard spasi Input.GetKeyDown Returns true during the frame the user starts pressing down the key identified by name (bernilai benar selama frame ketika pemain menekan keyboard yang diidentifikasi dengan namanya).

• Contoh di Unity documentation: void Update() {

if (Input.GetKeyDown("space")) print("space key was pressed");

}

Page 13: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Modifikasi contohvoid Update() {

if (Input.GetKeyDown("space")) {this.GetComponent<Rigidbody> ().AddForce (newVector3(0, 10, 0));

}}

Diinginkan: cube Player bergerak ke atas ketika pemain menekan keyboard spasi.

Berpindah tempat Pakai force

• Nilai x & z nol karena ketika pemain menekan spasi, cube Player HANYA HARUS bergerak ke atas, BUKAN menggelinding seperti cube Player di Roll a Ball.

• Karena cube Player HARUS bergerak ke atas, maka nilai y tidak boleh nol.

(seperti di Pertemuan 2)

Page 14: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Di game ini: void Update () {if (Input.GetKeyDown ("space")) {

this.GetComponent<Rigidbody> ().AddForce(new Vector3(0, jumpForce, 0));

a

}}

Di game Roll a Ball:private Rigidbody rb;void Start () {

rb = GetComponent<Rigidbody>();}void FixedUpdate () {

float moveHorizontal = Input.GetAxis ("Horizontal");float moveVertical = Input.GetAxis ("Vertical");Vector3 movement = new Vector3(moveHorizontal , 0.0f, moveVertikal);rb.AddForce (movement);

}

Di game ini: Rigidbody-nya tidak disimpan di variabel khusus rb.

Page 15: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Membuat cube Player bergerak ke kanan secara otomatis ketika game dijalankan

• Di Unity Documentation: search Rigidbody. Klik.– Di halaman penjelasan Rigidbody: Ctrl F velocity. Klik yang

hanya velocity (bukan angularVelocity, maxAngularVelocity, dll).

– Rigidbody.velocity: velocity vector of the rigidbody (vektor kecepatan rigidbody).

– Contoh penggunaan:

void FixedUpdate() { if (Input.GetButtonDown("Jump"))

rb.velocity = new Vector3(0, 10, 0); }

Karena cube Player diinginkan bergerak ke kanan secara otomatis ketika game dijalankan

Copas HANYA baris ini ke skrip

Page 16: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

rb.velocity = new Vector3(0, 10, 0);

Karena di game ini, Rigidbody-nya tidak disimpan di variabel khusus rb, maka skripnya harus diubah menjadi:

this.GetComponent<Rigidbody> ().velocity =new Vector3 (0, 10, 0);

xz

y Cube Player bergerak ke kanan: Buat variabel horizontalVelocity:

public float horizontalVelocity; this.GetComponent<Rigidbody>

().velocity = new Vector3(horizontalVelocity, 10, 0);

Page 17: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Karena kecepatan tiap komputer berbeda-beda: agar pergerakan cube Player tampak sama kecepatan baik di komputer berkecepatan rendah/tinggi:

this.GetComponent<Rigidbody> ().velocity = new Vector3(horizontalVelocity * Time.deltaTime, 10, 0);

horizontalVelocity perlu dikalikan Time.deltaTime

The time in seconds it took to complete the last frame

Ganti jadi this.GetComponent<Rigidbody> ().velocity.y

Ganti jadi this.GetComponent<Rigidbody> ().velocity.z

Agar nilai-nilai y & z-nya tetap

Page 18: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Set:

• Tekan Play mode

Page 19: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Lihat nilai-nilai Time.deltaTime dengan print:

this.GetComponent<Rigidbody> ().velocity = new Vector3 (horizontalVelocity * Time.deltaTime,this.GetComponent<Rigidbody> ().velocity.y,this.GetComponent<Rigidbody> ().velocity.z

);

print ("horizontalVelocity : " + horizontalVelocity +" ; Time.deltaTime : " + Time.deltaTime + " >> x: " + horizontalVelocity * Time.deltaTime);

Letakkan sebelum

Page 20: Pertemuan 5 Roll a Ball (Part 4) - WordPress.com · Pertemuan 5 Roll a Ball (Part 4) Mata Kuliah Logika Game Program Studi Teknologi Permainan Sekolah Tinggi Multi Media Yogyakarta.

Tekan Play mode

Tampak di Panel Console:• horizontalVelocity : 250 ; Time.deltaTime : 0.02 >> x:

5• horizontalVelocity : 250 ; Time.deltaTime : 0.3333333

>> x: 83.33334• horizontalVelocity : 250 ; Time.deltaTime :

0.07237727 >> x: 18.09432• horizontalVelocity : 250 ; Time.deltaTime :

0.02828782 >> x: 7.071956

Time.deltaTime: The time in seconds it took to complete the last frame