Application of AR Technology how to do a Pokemon go throw the Genie ball and grab Pikachu! (2)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

I didn't even guess I had 2.

Last talk about how to make Pikachu appear in "Reality".
This time, we're going to take the elf ball and catch the PI-mound! (PA pa

1. Create a sphere as a sprite ball, and then on the map. Ah! We're setting it up too big to feel like we can just drop the pickup. 2333


2. Next we are going to throw out the elf ball, which is actually a simple shooting game.
① record the position of the sprite ball first.

void     Span class= "Hljs-title" style= "Color:rgb (38,139,210)" >startset  ( )  {    Debug.Log ( "set Sprite ball Position" ); Resetpos = ball.transform.localPosition;}  

② according to the finger swipe, that is, click on the place and the finger to leave the place, to determine a force

void Update  () {if  (input . Getmousebuttondown (0 )) {downposx = input . mouseposition.x;  Downposy = INPUT.MOUSEPOSITION.Y; } if (Input.getmousebuttonup (0)) {upposx = input . mouseposition.x;  Upposy = INPUT.MOUSEPOSITION.Y; Shootend (); }}

③ gives the elf ball a force to shoot out

void  Span class= "Hljs-title" style= "Color:rgb (38,139,210)" >shootend   ()  { Targetcube.transform.position = new  Vector3 (( UPPOSX-DOWNPOSX) * 0.1f , (upposy-downposy) * 0.05f , (upposy-downposy) * 0.1f ); Ball. Getcomponent<rigidbody> (). Velocity = targetcube.transform.position;} 

④ if not shot, let the elf ball back to the beginning of the position

void  Span class= "Hljs-title" style= "Color:rgb (38,139,210)" >resetball  ( ) {this . Transform.rotation = Quaternion.euler ( Vector3.zero); Ball. Getcomponent<rigidbody> (). Velocity = Vector3.zero; Ball. Getcomponent<rigidbody> (). usegravity = false ; Ball.transform.localPosition = Resetpos; }

3. But pokeball to have a heavy feeling, after hitting Pikachu, the sprite shaking in the sprite ball animation.
① add rigibody, tick off use Gravity


② to Pokeball add animator, add animation, is actually k a simple rotation around the z-axis animation.


Did you catch it?

4. To make the elf ball hit Pikachu.
① Adding a collision body



② Add collision logic to Pokeball, hide Pikachu, play Sprite ball shake animation, play catch effect

void  Span class= "Hljs-title" style= "Color:rgb (38,139,210)" >oncollisionenter  ( Collision Collisioninfo ) {if  (Colli SionInfo.gameObject.name = =  "Pikachucosplay" ) { Pikachu. SetActive (false ); Getcomponent<animator> (). Enabled = true ; Effects. SetActive (true ); } }

-----------End------------


Come and catch your pikachu!

Welcome to shoot Bricks, praise ~

Beta apk (Android 5.1 +): Http://pan.baidu.com/s/1slaQ6ID

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.