Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Andrew85 · Jul 29, 2011 at 12:49 AM · random

Whack-A-Mole Issue

I'm in the process of making a whack a mole minigame and came across an issue: I can get all of the "Moles" (cylinder game objects made in Unity at the moment) to raise up to the proper height, but they all move at the same time. I need to make them move randomly up to that height and wait for a set amount of time before going back to their starting position. I already have the code for clicking the moles, detecting the hit, and adding to the score, I'm just having an issue making them move randomly and independent of each other.

 var pointB : Transform;
 private var pointA : Vector3;
 var speed = Random.Range(.5, 3);
 var offset = Random.value * 123;
 
 
 
 function Start () {
 
     pointA = transform.position;
     
 
 
 
 }
 
 function Update()
 {      
         var i = Mathf.PingPong(Time.time * speed, offset);
         //transform.position = Vector3.MoveUp(transform.position,OriginalTransform,Speed);
         
         if(transform.position == pointB.position)
         {
             //yield WaitForSeconds (5);
             
             print("We are here");
         }
           transform.position = Vector3.Lerp(pointA, pointB.position, i);
           
        
     
 }
 
 //waitforseconds
 //random
Comment
Add comment · Show 3
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 Andrew85 · Jul 29, 2011 at 01:19 AM 0
Share

Here is the working code I have handling the movement of the moles:

var pointB : Transform; private var pointA : Vector3; var speed = 1.0;

function Start () {

 pointA = transform.position;

}

function Update() {
var i = $$anonymous$$athf.PingPong(Time.time * speed, 1);

     if(transform.position == pointB.position)
     {
         print("We are here");
     }
       transform.position = Vector3.Lerp(pointA, pointB.position, i);
    
 

}

avatar image _Petroz · Jul 29, 2011 at 04:55 AM 0
Share

Oops I accidently deleted the first comment.

@Andrew: please put the code in your question and use the 010101 button to use code formatting so that it is readable.

avatar image Andrew85 · Jul 29, 2011 at 09:13 PM 0
Share

Sorry about that. I just edited the post, and also updated it with the suggestion from Warwick and a couple of the other things I attempted.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Waz · Jul 29, 2011 at 05:14 AM

In Start do:

 offset = Random.value * 123;

then add this var to the value passed to PingPong.

Comment
Add comment · Show 1 · 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 Andrew85 · Jul 29, 2011 at 09:10 PM 0
Share

That's really close. Please forgive me if this seems like a dumb question, but would changing the 123 lower the amount of time between movement? They all go to the top at different speeds, but they stay there for way too long. Thank you for the help, much appreciated!

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Simple array an spawning question 6 Answers

Make an object move towards random spot on another objects edge? 1 Answer

Puzzle + Grid Instantiate - Random 2 Answers

Make object move in random directions 1 Answer

InvokeRepeating with a variable? 2 Answers


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