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 SGamerXxX · Aug 16, 2012 at 09:15 PM · movementsimpletransform.translatey axisx axis

Alternative to transform.Translate?

Now was trying to create a simple movement script problem is that im using transform.Translate.See Here:

 var speed : int = 30; 
   
 function Update ()
     {
         var horizontal = 0;
         if (Input.GetKey(KeyCode.A)) horizontal = -1;
         if (Input.GetKey(KeyCode.D)) horizontal += 1;
         transform.Translate (horizontal * speed * Time.deltaTime*3, 0, 0);
         var vertical = 0;
         if (Input.GetKey(KeyCode.S)) vertical = -1;
         if (Input.GetKey(KeyCode.W)) vertical += 1;
         transform.Translate (0, vertical * speed * Time.deltaTime*3, 0);
     }

What I have different from most movement script I only want my character moving on the X and Y axes. (As it is always moving on the Z axis)

Now as you probably know transform.Translate does not have collision detection. I found that out the hard way. I was wonder if there was an alternative to transform.Translate that would do much the same thing (albeit with collision)

I was trying to get other things to work but thing like Input.GetAxis("Vertical")but it was not liking(not moving when attached to) the Y axis. I'm not sure if this was just incorrect syntax or not.

So to review , I'm am trying to get a simple movement script that has collision and moves on the X and Y axes.(Preferably no sliding)

And before you ask it has a Rigidbody and CharacterController attached to it.

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 CET · Aug 17, 2012 at 12:48 AM 0
Share

rigidbody.AddRelativeForce(); moves it relative to the current velocity / rotation AddForce moves relative to the world "velocity" and rotation

//along the xy plane

or rigidbody.AddForce(Vector3.right speed Time.deltaTime Input.GetAxis("Horizontal")); rigidbody.AddForce(Vector3.up speed Time.deltaTime Input.GetAxis("Vertical"));

avatar image SGamerXxX · Aug 17, 2012 at 01:09 AM 0
Share

Nope, doesn't seem to work, still no collision.

avatar image Sundar · Aug 17, 2012 at 01:38 AM 0
Share

Why do use both Rigidbody and CharacterController, check this

http://docs.unity3d.com/Documentation/Components/class-CharacterController.html

avatar image SGamerXxX · Aug 17, 2012 at 01:51 AM 0
Share

CharacterController component, not gameObject, Sorry if you got confused. And Ok I checked it but, what am I looking for?

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SGamerXxX · Aug 19, 2012 at 10:12 PM

Well i got it working (mostly) I switched out the character controller component with a box collider. That worked but it when flying off at weird rotations, that is until I locked the rotations by putting this

 transform.eulerAngles.x=0;
 transform.eulerAngles.y=0;
 transform.eulerAngles.z=0;

code into the Update Function. It now collides. Now if only I could get it to stop sliding when I collide.

Anyway thanks for your help even if I didn't use it , It did give me ideas on how to modify my code to work.

Comment
Add comment · 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
1

Answer by Rati_Old · Aug 17, 2012 at 01:37 AM

perhaps you should get your CharacterController

 CharacterController MyControl= GetComponent<CharacterController>();
 
 MyControl.Move(horizontal * speed * Time.deltaTime*3, 0, 0);

Comment
Add comment · 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
0

Answer by Rati_Old · Aug 17, 2012 at 01:37 AM

If you have a CharacterController, you could use it to move. It have a collision detection

 // declaration
 CharacterController MyControl = GetComponent<CharacterController>();
 
 // in your update
 MyControl.Move(0, vertical * speed * Time.deltaTime*3, 0);
 
Comment
Add comment · Show 1 · 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 SGamerXxX · Aug 17, 2012 at 01:48 AM 0
Share

First off, Edit your answer ins$$anonymous$$d of creating it twice, and second that doesn't work.

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

10 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

Related Questions

Moving on the Y Axis (Javascript) 2 Answers

Lerp movement speed 1 Answer

How to stop transform.Translate instantly ? 1 Answer

Mose look no limits 1 Answer

move character at constant speed, and detect collisions. 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