Forgot password?
 立即注册
EasyAR Portal Tutorial View Content

EasyAR Developing Cases---Pokemon Go (1)

AlbertLee 2017-8-23 09:46

Pokemon Go Developing Samples

Pokemon Go was the most popular AR game last year, which not only makes users experience intriguing AR effect but also excited developers. Here I am going to share how to build AR+LBS+IP, similar to Pokemon via EasyAR SDK.

I am going to build this App in the several tutorials. Main functions and tutorial catalogue are like this:


1..Achieve basic gesture of throwing in Pokemon Go

2.Integrate AR screen recording

3. take a photo, screenshotscreen recording,send them to social platform online.

4.Integrate LBS by Baidu Map and Amap

5.Add voice function

6.UI design

7.Add player killing functionPK between pokemons, that is online PK

........


Now my plan is like that. You can leave your comments below. Today we develop the first part-----throw pokeballs and capture Picachu.


Step 1:Developing Environment

Import developing resources and EasyAR 2.0 unitypackage into Unity. Like that:

Here I prepare many Pokeball models and you can choose as you will:


Drag EasyAR_Startup, Picachu model and pokeballs into HierarchyWe don’t need image target for we don’t display AR model via image target


Modify Picachu’s Position and Rotation in Transformfor better experience in mobile device.You can have appropriate numbers in testing. For example:


Modify Position of Pokeballs(very important):


Next, put Box Collider on Picachu and add Tagname it Pika




Add rigid body and sphere collider for pokeballs.




Step 2:Achieve throwing effect

The method is like that: click pokeball for parabolic movement. Here we have two ways of achieving that effect. One is by Rigid Body and another is by Transform.


The first method:

Create a script for Pokeball:


We mainly add forward thrust and upward momentum to achieve its movement after clicking the Pokeball. Then find Pokemon by raycast and make the pokeball slowly collide with pokemon via lerp.

After we set the speed of forward thrust and upward momentum, throwing effect is achieved. However, it is not flexible enough to collide Picachu.


The second method:


We achieve the effect by Tranform.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Throw : MonoBehaviour {
    public const float g = 9.8f;

    public GameObject target;
    public float speed = 10;
    private float verticalSpeed;
    private Vector3 moveDirection;

    private float angleSpeed;
    private float angle;

    bool drawing=false;
    void Start()
    {
        float tmepDistance = Vector3.Distance(transform.position, target.transform.position);
        float tempTime = tmepDistance / speed;
        float riseTime, downTime;
        riseTime = downTime = tempTime / 2;
        verticalSpeed = g * riseTime;
        transform.LookAt(target.transform.position);

        float tempTan = verticalSpeed / speed;
        double hu = Mathf.Atan(tempTan);
        angle = (float)(180 / Mathf.PI * hu);
        transform.eulerAngles = new Vector3(-angle, transform.eulerAngles.y, transform.eulerAngles.z);
        angleSpeed = angle / riseTime;

        moveDirection = target.transform.position - transform.position;
    }


    void OnMouseDown()
    {
        drawing = true;

    }

    private float time;
    void Update()
    {
        if (drawing) {
            time += Time.deltaTime;
            float test = verticalSpeed - g * time;
            transform.Translate (moveDirection.normalized * speed * Time.deltaTime, Space.World);
            transform.Translate (Vector3.up * test * Time.deltaTime, Space.World);
            float testAngle = -angle + angleSpeed * time;
            transform.eulerAngles = new Vector3 (testAngle, transform.eulerAngles.y, transform.eulerAngles.z);
        }
    }

}

Then drag this script for Picachu:



Step 3:Collision and Interaction

When pokeball collides with Picachu, we define it as Catch which destroy Picachu and pokenall and play the sound effect.

First, add “AudioSource” under “AudioSource”



Add function in the script:


void OnTriggerEnter(Collider col)
    {
        if (col.tag == "Pika") {
            sound.Play ();
            Destroy (col.gameObject);
            Destroy (this.gameObject,3f);
        }

    }


Now we can achieve catch and we will optimize it in the following tutorials. We can discuss together if you have any questions.

  • dunielson 2017-9-18 01:31
    Can you please share the asset files such as the pokeballs and pika models?  I'm looking forward to seeing this tutorial continue.  Thank you for sharing.