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 AnxoDL · Mar 03, 2014 at 07:04 PM · javascriptgameobjectaddforce

Trigger doesnt do Speed Booster

Hi everyone, i want that my ball get a speed booster when it crosses an object. For that i did this Script, but when the ball cross the box nothing happens. The box has rigidbody and default box collider. I probe with trigger off and trigger on. And i dont know how to do. Any idea? Thanks.

 var ballForce:uint = 40;
 
 function OnTriggerEnter(other:Collider)
 {
     if(other.gameObject.tag == "Ball")
     {
             var pelota:GameObject = other.gameObject;
             pelota.rigidbody.AddForce(0,0, (-1)*ballForce);
     }
 }
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 Nanobrain · Mar 03, 2014 at 07:31 PM 0
Share

Note that the trigger box does not require a rigidbody, only a collision box. That said, make sure that your ball has a rigidbody, a collision box, and it's tag is "Ball". Also, make sure that your script is attached to the trigger in the editor.

1 Reply

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

Answer by NoahConstable · Mar 03, 2014 at 11:06 PM

Hey AnxoDL, I used your script in my project and it worked. Here is what I did:

Change line 8 from:

 pelota.rigidbody.AddForce(0,0, (-1)*ballForce);

To:

 pelota.rigidbody.AddForce(-Vector3.forward*ballForce);

Now keep in mind, I'm assuming that your "AddForce(0, 0, (-1)*ballForce)" means you want the object to move back on the "Negative of the z-axis" upon impact with the trigger. If not change the keyword "-Vector3.forward" to the direction you want. If you need to know more, here is a link to the documentation on how to use Vector3 in AddForce:

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html

Also note 40, as an interger for how fast you move, is pretty small. I had to raise the number from 40 to 400 to see a difference. If you have any questions just comment on this. If this fixed your problem, please mark it as solved so others may see it, and ask there own questions to grow the Unity community.

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

22 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Help on selecting and unselecting a gameobject? 2 Answers

What variables can i declare? 1 Answer

Array problem -3 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