• 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 Lemo76 · Mar 23, 2013 at 10:06 AM · gameobjectphysicsposition

Boost Effect

I've got a gate that when the player goes through, it boosts in s certain direction (in this case, up). How do I do that cool boost effect without anything like AddForce or without it having a teleporter effect like I have just done:

// Make a Speed Effect function OnTriggerEnter (other : Collider) {

print ("fast"); other.gameObject.transform.position.y=other.gameObject.transform.position.y+10;

}

I want it like when you go through the gate it boosts you up.

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 fafase · Mar 23, 2013 at 10:12 AM

Here is a simple version:

 MovementWithBoost.js
 var speed:float = 5.0f;
 
 function Update(){
    
    transform.position.x += speed*Time.deltaTime*Input.GetAxis("Horizontal");
    while(speed > 5)speed-=Time.deltaTime;
 }

 Door.js
 
 function OnTriggerEnter(col:Collider){
    var script:MovementWithBoost = col.gameObject.GetComponent(MovementWithBoost) as MovementWithBoost;
    if(script != null)
        script.speed = 10;
 }

See if that does it. At least that should get you started. You may want to tweak value as your boost is about to decrease over 10 seconds. If you use something like:

 if(boost > 0)boost-=Time.deltaTime*boostDown;

you can reduce the period of boost but keep your boost high enough to be significant, it will just decrease faster (if boostDown is positif!!)

EDIT: The first script goes on any moving object you want to be able to be boost. The second goes ow on the door. When something collides with the door, the script checks if the object has the script. If not then script is null and the boost is not applied. If the object has one then the boost is applied.

EDIT AGAIN: I modified the script again to add the input.

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 Lemo76 · Mar 23, 2013 at 09:13 PM 0
Share

Haha thanks but, The problem is, if I add it to the gate, the gate moves forward. I want it so that I can add the script on a gate and I have variables which I can individually edit so that if anything touches the gate, it will be boosted in my variable direction.

avatar image Lemo76 · Mar 25, 2013 at 06:58 AM 0
Share

I did some testing and if I attach this to the gate/door:

var boost:float; var speed:float = 5.0f; var Player : GameObject;

function Update(){ Player.transform.position.x += (speed + boost)*Time.deltaTime; if(boost > 0)boost-=Time.deltaTime; else if(boost < 0 ) boost = 0; }

and I set Player to the main character, on the start it flings the player to the right. Now if I just:

function OnTriggerEnter(col:Collider){ Player.transform.position.x += (speed + boost)*Time.deltaTime; if(boost > 0)boost-=Time.deltaTime; else if(boost < 0 ) boost = 0; }

When I walk onto the right side of the gate, I get teleported back a tiny bit. Why is it doing that? To tell you more info, if I click on the gate while playing, when I hit the right side of the gate the count goes down.

avatar image fafase · Mar 25, 2013 at 10:54 AM 0
Share

You should not control your guy from the door script. That is just not logical.

With the input that may fix a little your teleporting issue.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Very Erratic behavior when parenting an object 0 Answers

How to tell if 2 blocks are next to each other in a 2d game? 1 Answer

Translate.transform problems (collision/Rigibody) 0 Answers

Position and rotation of a game object acting wired 0 Answers

Get enemy position in script 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