Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by missypooh · Mar 04, 2012 at 05:03 PM · animationscriptableobject

Formed puzzle piece and sense the existence of the character and enemy moving around

I have a few question and appreciate if anyone can help out.

  1. Basically player will go around the maze to collect the puzzle piece. After collecting the puzzle piece, it will direct them to a scene to match the puzzle piece. As i am creating chinese games, so the puzzle piece will only have two pieces. So what i want to ask is how to match the piece. http://imageshack.us/photo/my-images/839/post05.png/

  2. It is possible to "sense" that the person is coming near you? For example, player is walking toward someone and ask them some question.So what i want to do is when the person go near that someone, either the player click on the someone or the someone automatically sense that someone come near them?

  3. I will have an enemy prefab walking around the scene. So what i want to do is when the enemy go near the player, the player's BP will reduce by 10. As the enemy prefab required to walk around the scene, i have actually created an animation for it and checked the 'isTrigger'. So if player go near it, player's BP will be deducted. But there is no effect( mean that no deduct of BP) at all. And i am thinking to let the player kill the worm by "stepping" on it. Something similar to super mario. Argh.. how can i do it?

    if(hit.gameObject.tag == "worm") { HealthControl.LIVES -= 1; print(HealthControl.LIVES); // play a sound clip at the exact position we hit the object AudioSource.PlayClipAtPoint(hitSound, transform.position); }

*edit as my question are not very clear. sorry about that

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ByteSheep · Mar 04, 2012 at 05:55 PM

I guess the main idea would be to create prefabs/puzzle pieces that can be collected and then check to see if all have been collected? You could probably achieve this by making the puzzle pieces check for collision with the player (meaning player has walked into them/collected them) using the OnTriggerEnter or OnCollisionEnter function. This could look something like:

var collected : int = 0; var totalpieces : int = 10;

OnTriggerEnter(Trig : Collider) {

if(Trig.gameObject.name == "player") {

 collected++;    

 Destroy(gameObject);

 if(collected==totalpieces)
 {
    // go to the puzzle scene - all pieces are collected
 }

} }

This will check if the player has walked into the puzzle piece, then add one to the total collected pieces variable, then destroy/remove the puzzle piece and finally if all pieces are collected go to the puzzle scene. Let me know if anything in the code is unclear or if I misinterpreted your question :)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image missypooh · Mar 05, 2012 at 02:12 AM 0
Share

hello merry_christmas, thank you. you are right. i have actually figure out how to do it already. What bother me is the matching of the puzzle part.

As mention, i am creating chinese game, so it will be quite different from the normal jigsaw puzzle which requires alot of pieces to form it. So for my case, i only need two or three to become a "complete" puzzle. http://imageshack.us/photo/my-images/404/post005.png/ -> required player to find a missing piece. http://imageshack.us/photo/my-images/839/post05.png/ -> missing piece that player have found.

So i am headache how to match the two pieces correctly. As players will be collecting quite a number of pieces, then go to the scene and match it with the piece they collected. Any ideas how i can do it? thank you for spending time to help :)

avatar image ByteSheep · Mar 05, 2012 at 02:27 AM 0
Share

Hmm, so you'd need each pair to have a different id, but the two matching pieces to have the same. Are all pieces instantiated as the same prefab or have you created a prefab for each image/piece ? If you are instantiating all pieces with one prefab and setting each ones texture via script then you could also give them individual tags, for example pair-1, pair-2, etc. You could also use tags if you are creating a prefab for each though..

avatar image missypooh · Mar 05, 2012 at 02:44 AM 0
Share

ok. So after doing all this, how to do the validation part? Like comparing the tag they have? And usually when for$$anonymous$$g puzzle right, we will drag the piece to the respective place right, how to drag the puzzle piece to the position?

avatar image ByteSheep · Mar 05, 2012 at 03:00 AM 0
Share

To do the drag part you would have to check the mouse position and set the puzzle pieces position accordingly, here are some links that might help: http://answers.unity3d.com/questions/32807/instantiate-object-at-mouse-position.html and http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenToWorldPoint.html . Then perhaps check if a piece is touching another using OnTriggerEnter and then check if both have the same tag name. Perhaps like this:

OnTriggerEnter(Trig : Collider) {

if(Trig.gameObject.tag == gameObject.tag) { //both pieces have same tag/are fitting pieces }

}

avatar image
1

Answer by ByteSheep · Mar 04, 2012 at 05:20 PM

You can use this to check the distance between two objects:

var other : Transform;

function Update() {

if (other) { var dist = Vector3.Distance(other.position, transform.position); print ("Distance to other: " + dist); }

if(dist<4) { //player is close enough print ("Player is close enough"); } }

Add this to each puzzle prefab and set the variable other to the player object in the inspector view.

Don't quite know what you mean with the puzzle pieces, hope this helps with question 2 though :)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image missypooh · Mar 04, 2012 at 05:41 PM 0
Share

hi thank you. I will try it out. Regarding the puzzle piece, it is quite similar in playing jigsaw puzzle. So in the beginning, i will show the players all the missing pieces for the jigsaw puzzle, so the players have to walk around the maze to find the missing piece. Any ideas how i can go about doing it?

avatar image missypooh · Mar 05, 2012 at 02:58 AM 0
Share

anyway regarding this code, where should i put it to?? The player? and the code i should put it in the update function?

avatar image
1

Answer by ByteSheep · Mar 05, 2012 at 03:12 AM

Afraid I can't edit the answer directly so here it is again:

 var other : Transform;
 
 function Update() {
 
   if (other) {
     var dist = Vector3.Distance(other.position, transform.position);
     print ("Distance to other: " + dist);
   }
 
   if(dist<4)
   {
   //player is close enough
   }
 }

Add this to the puzzle prefab and set the variable "other" to the player object in the inspector view of the prefab.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Collide with worm deduct BP and kill the worm 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Perform Action on frame/time of animation 1 Answer

How to create an animation hands (or script) to pick-up a cup from the table in 3ds max or maya or from direct unity! Please help!! 2 Answers

How to get gun to move with models hand? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges