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 Kiraisuki · Jan 25, 2014 at 02:51 AM · first person controllerpushcurrentriver

How Do I Make A River With A Current?

I have a standard Unity First Person Controller, and a cube in some terrain made to look like a river. How would I go about making it so when the player walks into the river, they are pushed in a certain direction? Like if the river had a current and wasn't just an aesthetic piece of scenery?

Comment
Add comment · Show 4
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 getyour411 · Jan 25, 2014 at 02:56 AM 0
Share

$$anonymous$$ore difficult than it sounds. First, how do you know when the player is "in" the river - do you have a trigger, are you using physics/colliders, etc. Second, what direction? Is the river a fairly straight affair moving in a generally constant direction, or does it twist and turn?

avatar image Kiraisuki · Jan 25, 2014 at 03:01 AM 0
Share

I'm trying to use a trigger, and the river is flowing in one general direction, with no major turns.

avatar image superventure · Jan 25, 2014 at 03:11 AM 0
Share

Simple- use transform.Translate(Vector3.forward * Time.deltaTime); you could use left ins$$anonymous$$d of forward for the vector3 Or you could slerp the position using slerp. You could also push the character with an invisible box collider told to move in the direction you want

avatar image getyour411 · Jan 25, 2014 at 05:23 AM 0
Share

I see a problem using a Vector3.forward or right/left, as the player turns so to does the direction the current is pushing in so that if I start moving right to left/downstream and then turn around, I'm now pushed "upstream".

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by getyour411 · Jan 25, 2014 at 06:35 AM

@superventure had a good suggestion after all, I just forgot to put Space.World in my Translate; once I did that it worked pretty well.

I placed a large cube/as a trigger sized approx to the river and added script

 using UnityEngine;    
 public class QM_Current : MonoBehaviour {
 
     void OnTriggerStay (Collider other) {
         if(other.tag == "Player") 
             other.transform.Translate(-Vector3.right * Time.deltaTime, Space.World);
         
     }
 
 }

(for a current going right to left, change the Vector3.dir to suit your needs.

Comment
Add comment · Show 5 · 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 Kiraisuki · Jan 25, 2014 at 04:11 PM 0
Share

I tried adding this script as both a javascript and c#, but they both give errors. changing the 'void' to 'function' in javascript makes it compile, but it then does nothing. putting it in c# causes it to throw a namespace error.

avatar image getyour411 · Jan 25, 2014 at 06:46 PM 0
Share

this is a snippet and doesn't contain the necessary public class blahblah using blahblah stuff; add that

Edit: I updated it for copy/paste

avatar image Kiraisuki · Jan 25, 2014 at 08:43 PM 0
Share

That would make sense, I'll test it out once Unity finishes updating.

EDIT: I tested the script and it worked great! There is one problem though, it appears that if the player is pushed into terrain in a certain direction, they fall through it. Is that the script or is that just a little thing with the Unity engine?

avatar image getyour411 · Jan 25, 2014 at 09:23 PM 0
Share

Script. $$anonymous$$oving things with transform.XXXX (tran/pos) can cause terrain fall throughs, you could add something to lock the position.Y that's usually the culprit. Are you using the standard First Person Controller in your overall game design, as is with no changes/new colliders/etc planned? $$anonymous$$nowing more about your game mechanics and ultimate player setup should deter$$anonymous$$e the route you should go in.

avatar image Kiraisuki · Jan 25, 2014 at 10:48 PM 0
Share

I'm using the default first person controller, it has an extra object parented to the camera (a torch with particles and a point light, but that doesn't collide with anything), it's got 2 GUI displays and a pause script attached to it, and it's got a script to allow it to collect items like coins. No colliders or anything else besides the above has been changed, and as far as I can tell, I won't be modifying it further.

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

19 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

Related Questions

A node in a childnode? 1 Answer

Unity Error: “Class defined in script does not match file name” happens after pushing to version control 1 Answer

Make First Person Controller small? Help 1 Answer

Push an object along a path? 2 Answers

Unity MultiPlayer Game Implementation Requirements. 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