• 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 /
  • Help Room /
avatar image
Question by Deaninboston · Jan 01, 2016 at 07:07 AM · scripting probleminputtriggerif-statements

Linking Trigger to Input (or directly into Character Control script)

**I have created an AR array using Vuforia that will move a placeholder relative to the camera's position (when the user moves the camera). I have attached t$$anonymous$$s placeholder to a collider object, w$$anonymous$$ch is surrounded by barriers, w$$anonymous$$ch are triggers. I want to substitute the triggers as button inputs for the character controls.

The idea is allow the player to cause their character to maneuver in the (FPS) game by changing the position of the camera forward, backwards, left, and right (relative to a marker). For a VR headset equipped with a camera, t$$anonymous$$s will allow the player to control a character by making small movements of their body, for more immersive play.

In the script that comes with the FPS Rigid Body Character Controller (Standard Assets, Unity 5.0), I t$$anonymous$$nk I've found the reference to the input controls:**

public void UpdateDesiredTargetSpeed(Vector2 input)

         {

             if (input == Vector2.zero) return;

             if (input.x > 0 || input.x < 0)

             {

                 //strafe

                 CurrentTargetSpeed = StrafeSpeed;
             }

             if (input.y < 0)

             {

                 //backwards

                 CurrentTargetSpeed = BackwardSpeed;
             }

             if (input.y > 0)

             {

                 //forwards

                 //handled last as if strafing and moving forward at the same time forwards speed should take precedence

                 CurrentTargetSpeed = ForwardSpeed;

             }


**I believe I need to replace the "if (input.y < 0)" with a reference to the trigger that is in front of the collider object, w$$anonymous$$ch the player is moving around by moving the camera. I don't really know how to do that, w$$anonymous$$ch I'll come back to at the end.

Likewise, the "if (input.y < 0)" should be replaced with a reference to the trigger be$$anonymous$$nd the collider object.

I'm not sure what to do with the side-to-side part, though: they changed up the syntax somehow and made that control "if (input.x > 0 || input.x < 0)"

So I have two problems.

1) How do I put a reference to the trigger (did the placeholder collide with the particular barrier) into the Character Controller script, and

2) How do I deal with the x-axis input, I have no idea what to do with t$$anonymous$$s departure from the previous format...t$$anonymous$$s is kind of a minor side question...please help me with #1, primarily!**

Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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

41 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

Related Questions

Having terrible trouble with GUIText 0 Answers

ANIMATION STRANGELY DOES NOT PLAY 0 Answers

Custom input not appearing in input manager 0 Answers

How to I create a light flash whenever the space bar is pushed? 0 Answers

If statement not working. 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