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 zxpecky · Mar 02, 2015 at 01:44 PM · rigidbody2d

Rigidbody2D speed boost when entering a trigger

I am making a 2D game and I want a 2D rigid body to get a speed boost when entering a 2D trigger, but I cannot get it to work. The object is not getting a speed boost. I am new to coding and am coding in C#. Here is the script I have.

     void OnTriggerEnter2D(Collider2D other) 
     {
         rigidbody2D.AddForce(Vector2(10, 0));   
     }
   






Comment
Add comment · Show 2
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 hexagonius · Mar 02, 2015 at 02:47 PM 0
Share

Is this code even triggering?

Is it attached to the player, not the pickup?

$$anonymous$$aybe 10 is not strong enough

Change the Forcemode for different results

Are you changing the rigidbody's velocity somewhere (Update, FixedUpdate)?

avatar image zxpecky · Mar 02, 2015 at 07:46 PM 0
Share

I have the script attached to the trigger not the player. I want the object with the tag "Player" to be pushed in the positive x direction upon entering the trigger zone. I have changed the script to only affect the player object and increased the force to 100. I am not getting any errors but the object still does not get a boost in speed when it enters the trigger zone. I am not changing the velocity of the rigidbody anywhere. This is the entire script that is attached to the trigger now.

 using UnityEngine;
 using System.Collections;
 
 public class Boost : $$anonymous$$onoBehaviour {
 
     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.tag == "Player")
         {
             rigidbody2D.AddForce(Vector2(100, 0)); 
         }
 
     }
 }

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Mar 02, 2015 at 08:20 PM

If you just call rigidbody2D then you're referring to the triggers. Put other. In front of it

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
avatar image
0

Answer by 10XL · Sep 15, 2015 at 10:56 PM

You need to access Rigidbody2D of Collider2D other that is entering the trigger. Keyword new is required for constructors. void OnTriggerEnter2d (Collider2D other) { other.GetComponent<Rigidbody2D> ().AddForce (new Vector2(10f, 0f)); }

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
avatar image
0

Answer by Jeason1997 · Sep 16, 2015 at 03:37 PM

If you use Unity5, you can use the "Area Efctor 2D" compoent to make this

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

AddingForceAtPoint not doing anything 0 Answers

Character does not jump 1 Answer

Unity C# 2D Adding Velocity on rotation 1 Answer

How many Kinematic rigidbodies(2D) can i have in a device game without any lag ? 0 Answers

More force depending on if mouse is clicked or held 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