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 gazza529 · Oct 25, 2013 at 10:21 AM · collidertransformgui-button

detect collider with button movement

Hi there I have 2 control systems in my project. One the general mouse look and keyboard movement. The other uses buttons to control all movement. Unfortunately the buttons override the ability to collide and stop at walls/doors etc. I thought of using raytracing but I'm unsure whether this would stop you from walking sideways through walls. Heres the code i'm using any advice would be great.

 var speed : float = Time.deltaTime * 100;
 if (movement==1){
  transform.Translate(0,0,speed);
  fly =0;
  }
  if (movement==2){
  transform.Translate(0,0,-speed);
   fly =0;
  }
   if (movement==3){
  transform.Translate(-speed,0,0);
   fly =0;
  }
   if (movement==4){
  transform.Translate(speed,0,0);
   fly =0;
  }

 
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
1
Best Answer

Answer by mattssonon · Oct 25, 2013 at 10:37 AM

When you use .Translate() you're most likely just moving the character to the other side of the collider, .e.g it's like teleporting not moving. You should use a different method, e.g. if it's a CharacterController, use .Move() or .SimpleMove().

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 gazza529 · Oct 25, 2013 at 11:27 AM 0
Share

thank you matt that works!!! Is there anyway of grounding the object? when i use a rigid body it still falls through

avatar image mattssonon · Oct 25, 2013 at 12:48 PM 0
Share

Great. Which object do you want to be grounded? What does it fall through? Feel free to accept the answer if it helped, so the question is categorized as solved for other visitors.

avatar image gazza529 · Oct 25, 2013 at 02:39 PM 0
Share

hi matt new problem has arisen. This script works for moving but it only moves along the axis not the way your facing.

     if (movement==2){
       transform.GetComponent(CharacterController).$$anonymous$$ove(Vector3.forward*speed);}
 Heres attempts but they make no difference
       if (movement==6){
      transform.Rotate(0,speed,0);}
 
       if (movement==5){
         transform.Rotate(0, Input.GetAxis ("Horizontal") * speed, 0);}

thanks for all your help

avatar image mattssonon · Oct 27, 2013 at 08:34 PM 0
Share

Try using transform.forward ins$$anonymous$$d of Vector3.forward, since Vector3.forward is just a vector pointing in the Z direction, which is not always the direction you're facing.

avatar image gazza529 · Oct 29, 2013 at 08:09 AM 0
Share

fantastic i assumed it was my rotation method that was off but it was the translation moving along the world axis thanks so much heres some of the working code for anyone with this problem in future.

 var speed : float = Time.deltaTime * 100;//adjust the figure according to the scale of your scene//
 if (movement==1){//forward button//
  transform.GetComponent(CharacterController).$$anonymous$$ove(transform.forward*speed);
  }
 
   if (movement==5){//rotate left//
   transform.Rotate(0,-speed,0);
  } 

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

16 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

Related Questions

Im trying to create a word game with a twist 0 Answers

Destory/Collect object to open door 1 Answer

Disabling or Destroying more lagless/ Do colliders and transforms work while disabled? 1 Answer

Strange Physics being applied to objects issue. 1 Answer

After building move doesnt move 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