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 PrincessPiranha · Sep 13, 2011 at 11:05 AM · collisionrotatemove

After collision rotate and move

I have been trying to make a spawning object move around, make collision, then rotate and move an other direction again. My world has a ground, which has some level difference at some points en walls surrounding it. I have a empty GameObject that spawns a ball. I want the ball to keep moving around and bounce of walls once it makes collision.

The spawning, collision and rotation work fine. But I somehow can't keep the prefab, which is a simple ball in my case and a rigidbody, to keep moving around the surface. The walls have a Boxcollider.

Can someone please help me? Struggling with this problem for some weeks now and it's driving me crazy. :) I have tried many many things and lost sight of it a bit.

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

1 Reply

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

Answer by roamcel · Sep 13, 2011 at 11:45 AM

Given the lack of information you're supplying regarding 'keep moving around the surface', I suppose that your issue is related to a common difficulty, which is understanding the DIRECTION of movement.

Quite simply, I suspect that you might not be making the object turn the appropriate angle around the world y axis, once it hits an obstacle.

  - access the collision procedure
  - add a Debug.Log("I collided"); instruction to it
  - add the following to the same procedure
 Quaternion newrotation = Random.rotation();
 transform.rotation = newrotation;

In the case that the object actually does something resembling a random new direction, post how you calculate the new direction after bounce.

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 PrincessPiranha · Sep 13, 2011 at 12:00 PM 0
Share

Oh the Y axis... I think I was working with Z all the time. I don't have anything working atm, but I worked with addForce. Do I have to apply a new force everything it collides? Or will that keep doing so after it made collision, if it is placed in a Update function? I will edit the main post to make my idea more clear. Thanks anyway!

avatar image roamcel · Sep 13, 2011 at 01:12 PM 0
Share

In unity's world coordinates, rotation around Z makes the object 'drill' forward. Turning in world coordinates require Y rotations, in fact.

Additionally, yes, you are possibly required to apply a new force upon collision since, in the case that you're using a rigidbody, the object loses momentum once it hits an obstacle.

If you're ins$$anonymous$$d altering the TRANSFOR$$anonymous$$ (which you should not do if the object has a rigidbody), then yes you should change the object direction in the Update function, rather than OnCollision.

avatar image PrincessPiranha · Sep 22, 2011 at 08:28 AM 0
Share

I got it to work a few days ago! Thank you for helping me out :)

function Update() { transform.Translate(Vector3.forward * Time.deltaTime); }

 function OnCollisionEnter(theCollision : Collision){
     if(theCollision.gameObject.name == "$$anonymous$$ountainPrefab"){
         rigidbody.transform.eulerAngles.y = Random.Range(20, 180);
         rigidbody.transform.Translate(Vector3.forward * Time.deltaTime);
     }
 }<code>

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Move a rigid body in an area of a platform 0 Answers

How to roll a ball ? 2 Answers

Help with plat-former character rotate 1 Answer

movement doesnt stop when jump pad is tapped at the same time 0 Answers

On Collision, Play Sound If Button Is Pressed 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