• 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 zacharif · Dec 13, 2019 at 12:18 AM · 3dfollowclone

How to clone on collision

Hello! I know this is a duplicate but I do not understand. Is there any way to periodically clone, (Like every 5 seconds) on collision? I tried scripts kindly provided by the people who answer here, but the scripts spawn away from the player. Eg: Player is at Z 560 but the spawn is at Z 1, I also tried multiple follow scripts including:`

 // Start is called before the first frame update
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {
     transform.position = player.position + offset;
 }

}

But it does not follow and instead causes bugs, any ideas? Here the code I got so far

 void Start()
 {
     FindObjectOfType<Moveafter>().enabled = false;
     FindObjectOfType<clonefor4>().enabled = false;
 }

 // Update is called once per frame
 void Update()
 {

 }

 IEnumerator OnCollisionEnter(Collision collisionInfo)
     {
         if (collisionInfo.collider.name == "Activateblock1")
     {
             FindObjectOfType<Moveafter>().enabled = true;
             FindObjectOfType<clonething>().enabled = true;//clone script
             FindObjectOfType<finalmoveplayer>().enabled = false;
             yield return new WaitForSeconds(50); 
             FindObjectOfType<finalmoveplayer>().enabled = true;
             FindObjectOfType<Moveafter>().enabled = false;
             FindObjectOfType<clonething>().enabled = false;
     }
     }
 

} ` Thanks!

Comment
Add comment · Show 6
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 zacharif · Dec 13, 2019 at 12:21 AM 0
Share

By the way, I cut off the code to void start

avatar image GanemVisk · Dec 13, 2019 at 01:55 AM 0
Share

Did you add a Debug.Log(player.position) in that Update before you set the position to check if it is what you expect? What is the value of offset? Also, if you just want the object to have an offset from the player, you can parent it to the player object with a local position equal to the offset.

avatar image zacharif GanemVisk · Dec 13, 2019 at 11:33 PM 0
Share

Thanks for replying! Yes, I tried everything you mentioned. For future reference, the parent does not work because my rigidbody is kinematic. Sorry if I worded it wrong, I meant if the player was somewhere, the clone will clone with an offset of the player. In simpler terms, if I want the clone to clone in plane 7, it will clone in the object with the cloning script and not clone in plane 1. Sorry again, I hope you understand what I mean now. Thanks!

avatar image WheresMommy · Dec 14, 2019 at 06:10 AM 0
Share

Are you sure your FindObjectOfType is finding the right one? If the script is on the collided one, you should do collisionInfo.collider.GetComponent ins$$anonymous$$d

avatar image zacharif WheresMommy · Dec 15, 2019 at 02:40 AM 0
Share

Ok, thanks! But do you know how to clone on a single game object? Thanks for helping out.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

151 People are following this question.

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

Related Questions

Cloning a game object. 1 Answer

How to clone with a object. 3 Answers

Same objects following different tags in Unity3D 2 Answers

GUI Follow RaycastHit 2 Answers

How to clone randomly 2 0 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