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
1
Question by Bumbob · Aug 04, 2014 at 04:20 AM · javascriptcollisionvector3functiontransform.position

How would I move an Object after collision?

I have my game set up in 2D mode, There is a side scrolling camera with a bar that follows it, during the game bricks will move across the screen, when they disappear off screen I am trying to get them to collide with the bar following and the move back by an x value of Random.Range(-6,-8) I am unaware if my code is wrong, or if I have an error, but I will post what code I have used.

     function OnCollisionEnter(collision:Collision){
     collision.transform.position = Vector3(Random.Range(-6,-8), Random.Range(-3,6),0);  
      }
 
Comment
Add comment · Show 1
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 tyrike thompson · Aug 04, 2014 at 04:42 AM 0
Share

What does the error say?

1 Reply

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

Answer by Noob_Vulcan · Aug 04, 2014 at 04:41 AM

If your bar collider is moving right then Just Make Sure that

  1. Your bricks/Bar has RigidBody. Because Collision is detected by Physics. So you will have to make one of them rigidbody.

  2. If you have Followed Step 1 and still your code is not working then you have problem in bar position. Just make the Bar child of camera.

I hope this should resolve your problem.

Comment
Add comment · Show 3 · 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 Bumbob · Aug 04, 2014 at 04:45 AM 0
Share

as I was thinking about it more, is that going to always move the bricks to that set random range, or will it continue pushing them back, my goal is to make them get pushed back every time they are collided with.

avatar image Noob_Vulcan · Aug 04, 2014 at 05:04 AM 0
Share

can u tell me what exactly u want to achieve so that i can help u.

avatar image Bumbob · Aug 07, 2014 at 10:32 PM 0
Share

I figured it out, in case anyone else needs the code, here it is

 function OnCollisionEnter (col : Collision)
 {
     if(col.gameObject.name == "WallL")
     {
         transform.position = Vector3(transform.position.x - Random.Range(-16,-20), Random.Range(-3,6),0);        
       }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Script error: respawn upon collission 2 Answers

Vector3 of moving object always returns (0,0,0) 1 Answer

Respawn when a character hits an object with a tag of "Kill" , but after 3 deaths the controller is destroyed 0 Answers

Object Collision PLEASE HELP!!! 1 Answer

Javascript Movement Script. Why am I getting these errors? 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