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

AR interactive examples - Fun zombies

AlbertLee 2017-8-8 10:18

AR interactive examples - Fun zombies

From the last tutorial, EasyAR developing skills---model interaction, we learned some popular mobile AR interaction techniques. Now, we are learning more based on the last tutorial, with an App thats similar to Sight Plus App to review and get familiar with AR interaction techniques.

Preview:



Resources: https://drive.google.com/open?id=0B6vjKDkZUGVsNGh4LVMxckNYRnc

Itween : https://drive.google.com/open?id=0B6vjKDkZUGVsam45N3lxNWtyWlU


Step 1:Developing preparation


Download EasyAR SDK, set up environment.lets delete Main Camera and drag EasyAR_Startup camera  in Hierarchy instead.


                  


Then, drag the monster model under Hierarchy (Notes: we havent used Imagetarget yet since it doesnt require recognition function.)


                 


Step 2:Modify parameters

First, adjust AR cameras angle, rotate X to 270 degree.


Then, rotate Y to 180 degree, and enlarge it twice. Change the default animation. (You dont have to, just makes it look better)


                 


Add BoxCollider for the monster, click on 'is Trigger'


Step 3:Click on monster to play interactive animation


First, add Animation for the object. You can add any animation according to your favor.


                    


Create a script to achieve animation interaction. The script is simple, and we have talked about it in the last tutorial. You can use the overall format.


using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{       
public Animation anim;       
void Start()       
{               
anim = GetComponent();
}
void Update()
{
if (!anim.isPlaying) {
anim.Play ("2HitCombo");
}
}
void OnMouseDown()
{
anim.Play ("jumpAttack_RM");
}
}

Now, we need to develop zoom functions with two fingers operation, drag function with one finger. This script has been used in the last tutorial (EasyAR developing skills---model interaction). You can save those common scripts for later usage. Drag those scripts directly onto the model.


step 4:Move to wherever is clicked.


Here, I only offer one way to develop this function. Of course, there are many more ways to achieve this effect.

First, we need to create a plane, modify its size to (2, 2, 2)


                       


                       

Next, change its Tag to Ground


                       


Heres an important tip, close Renderer so that it wont show up. Here we only need Mesh Collider.


                      


                      


We can create a script on the model. We can create the function by Raycast.

We can use Input.touchCount to check if theres any touch event. Get Input.GetTouch(0).position, touch phones screen, then raycast it to make it move. The entire script is like below:


using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
private Vector3 clickPosion;
public float speed = 5f;
void Start()
{
clickPosion = transform.position;
}
void Update()
{
if (Input.touchCount > 0) {
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch (0).position);
RaycastHit hit;
Physics.Raycast(ray, out hit);
try
{
if (hit.collider.tag == "Ground")
{
Vector3 v = hit.point;
clickPosion = new Vector3(v.x, transform.position.y, v.z);
transform.LookAt(clickPosion);
}
}
catch
{
}
iTween.MoveTo(gameObject, clickPosion, 4f);
}
}
}