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 unity_2003el612003fy9 · Feb 03, 2019 at 12:36 AM · triggerspeedboost

How to increase the speed of an object's movement when it enters a trigger?

This is my first Unity3D assignment, and could use some help.

I'm basically making my own Rube Goldberg model, and I want to make the moving sphere speed up when it reaches this roller-coaster loop, as shown in my poorly drawn sketch. For example, when it collides with the green area, it is triggered to speed up so it would have enough momentum to reach the other end.

I can't for the life of me find any tutorials anywhere, and I'm an absolute beginner at programming.alt text

img-2665.jpg (322.5 kB)
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

Answer by Magso · Feb 03, 2019 at 01:18 AM

 //Speed and acceleration variable
 float speed, accel;
 
 void OnTriggerEnter (Collider other)
     {
     //check if the other collider is tagged as "Area"
     if(other.tag == "Area")
         {
         speed += accel;
         }
     }
 
  //to move the object you can either use addforce or translate.
 
 void FixedUpdate
     {
     GetComponent<Rigidbody>().AddForce(0, 0, speed * Time.DeltaTime);
     }
 
 //or
 
 void Update
     {
     transform.Translate(0, 0, speed * Time.DeltaTime);
     }
 
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 Magso · Feb 03, 2019 at 01:22 AM 0
Share

Forgot to mention, this script goes on the ball and the ball needs a trigger collider, the area can be a kinematic rigidbody.

avatar image unity_2003el612003fy9 Magso · Feb 03, 2019 at 01:51 AM 0
Share

Hey thanks for the help. For some reason when the 'Is Trigger' box on the ball is ticked, the ball fails to collide with anything and simply just goes through all the objects in the scene. Any idea why this might be happening?

avatar image Magso unity_2003el612003fy9 · Feb 03, 2019 at 02:08 PM 0
Share

The ball would need a second collider that is set as a trigger. Also the area to speed it up would have to be set as a trigger as well to avoid collision with the ball.

There are two ways you can set this whole thing up, either have a single script on the ball (which was my first answer) or have a script for the ball,

 float speed;
 
 void FixedUpdate
     {
     GetComponent<Rigidbody>().AddForce(0, 0, speed * Time.DeltaTime);
     }
 
   //or
 
 void Update
     {
     transform.Translate(0, 0, speed * Time.DeltaTime);
     }

And another script for the area.

 float accel;
 
 void OnTriggerEnter (Collider other)
      {
      //check if the collider is tagged as "Player" this time.
      if(other.tag == "Player")
          {
          other.GetComponent<ScriptName>().speed += accel;
          }
      }

This way the ball doesn't need to have a trigger.

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

119 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

Related Questions

Adding Speed to onTriggerEntered 1 Answer

Ideas for detecting collision speed with trigger? 2 Answers

Boost Script Time problems 1 Answer

Unity car tutorial speed boost 1 Answer

Below script is a car controller and i want the car to boost when hit a trigger object. Still new with unity T^ T 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