Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Sep 03, 2016 at 03:35 PM by Somniothedreamer for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Somniothedreamer · Aug 25, 2016 at 11:40 AM · movementtransform.translate

Why is transform.translate not working?

 float drehen;
 Vector3 Richtung = new Vector3(0f,0f,1f);
 // Use this for initialization
 void Start () {
     drehen = 1;
     Richtung = Vector3.left;
 }
 
 // Update is called once per frame
 void Update () {
     transform.Translate (0.1f*Vector3.left*Time.deltaTime);
 }

hi there

This is the beginn of a script to controll the movement of my robot. But I have a problem. transform.Translate doesn't move it at all. What did i wrong? Could anyone help me please?

thanks

Comment
Add comment · Show 3
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 Somniothedreamer · Aug 26, 2016 at 09:03 AM 0
Share

I changed my Version of unity from 5.4.0f3 to 5.3.2f1 and now this part is working. But as soon as i completed my script, i recognised, that the second part with the OnTriggerEnter is doing nothing. But i now that the scriptt is going throug on trigger because the System reports, if i write in a undefined tag. float drehen; Vector3 Richtung = new Vector3(0f,0f,1f); private Animator anim; // Use this for initialization void Start () { drehen = 1; Richtung = Vector3.forward; anim = GetComponent (); }

 // Update is called once per frame
 void Update () {
     transform.Translate (2.8f*Richtung*Time.deltaTime, Space.World);
 }
 void OnTriggerEnter(Collider other){
     if (other.CompareTag ("z+")) {
         if (drehen == 2) {
             drehen = 1;
             Richtung = Vector3.forward;
             anim.SetBool("right",true);
             StartCoroutine (delay ());
             transform.Rotate (Vector3.forward, Space.World);
             anim.SetBool ("right", false);
         }
         if (drehen == 4) {
             drehen = 1;
             Richtung = Vector3.forward;
             anim.SetBool("left",true);
             StartCoroutine (delay ());
             transform.Rotate (Vector3.forward, Space.World);
             anim.SetBool("left",false);
         }
     }
     if (other.CompareTag ("z-")) {
         if (drehen == 2) {
             drehen = 3;
             Richtung = Vector3.forward;
             anim.SetBool("left",true);;
             StartCoroutine (delay ());
             transform.Rotate (Vector3.back, Space.World);
             anim.SetBool("left",false);
         }
         if (drehen == 4) {
             drehen = 3;
             Richtung = Vector3.forward;
             anim.SetBool("right",true);
             StartCoroutine (delay ());
             transform.Rotate (Vector3.back, Space.World);
             anim.SetBool("right",false);
         }
     }
     if (other.CompareTag ("x+")) {
         if (drehen == 1) {
             drehen = 2;
             Richtung = Vector3.forward;
             anim.SetBool("right",true);
             StartCoroutine (delay ());
             transform.Rotate (Vector3.right, Space.World);
             anim.SetBool("right",false);
         }
         if (drehen == 3) {
             drehen = 2;
             Richtung = Vector3.forward;
             anim.SetBool("left",true);
             StartCoroutine (delay ());
             transform.Rotate (Vector3.right, Space.World);
             anim.SetBool("left",false);
         }
     }
     if (other.CompareTag ("x-")) {
         if (drehen == 1) {
             drehen = 4;
             Richtung = Vector3.forward;
             anim.SetBool("left",true);
             StartCoroutine (delay ());
             transform.Rotate (Vector3.left, Space.World);
             anim.SetBool("left",false);
         }
         if (drehen == 3) {
             drehen = 4;
             Richtung = Vector3.forward;
             anim.SetBool("right",true);
             StartCoroutine (delay ());
             transform.Rotate (Vector3.left, Space.World);
             anim.SetBool("right",false);
         }
     }
 }
 IEnumerator delay(){
     yield return new WaitForSeconds (5);
 }
avatar image mj321 · Aug 26, 2016 at 09:19 AM 0
Share

The "StartCoroutine (delay ());" doesn't actually delay the program flow. The code will continue immediately. You can only wait inside a CoRoutine. Otherwise you'd block the program.

avatar image Somniothedreamer · Aug 28, 2016 at 12:24 PM 0
Share

Thank you I changed some things and now everything is just working fine except the rotation. It should rotate immediately with no interpolation, but at the moment he's jjust doing nothing. using UnityEngine; using System.Collections; [RequireComponent(typeof(CapsuleCollider))] public class behavior : $$anonymous$$onoBehaviour { float drehen; Vector3 Richtung = new Vector3(1f,0f,0f); private Animator anim; private Rigidbody body; public Quaternion rotieren=Quaternion.Euler(new Vector3(1f,0f,0f)); // Use this for initialization void Start () { drehen = 1; Richtung = Vector3.forward; anim = GetComponent (); body = GetComponent (); body.velocity =5*Richtung; rotieren=Quaternion.Euler(new Vector3(0f,1f,0f)); }

 // Update is called once per frame
 void FixedUpdate () {
     body.$$anonymous$$oveRotation(rotieren);
 }
 void OnTriggerEnter(Collider other){
     Debug.LogWarning("in OnTriggerenter Event");

     if (other.CompareTag ("z+")) {
         if (drehen == 2) {
             drehen = 1;
             Richtung = Vector3.forward;

             anim.SetBool("right",true);
             StartCoroutine (delay ());
         }
         if (drehen == 4) {
             drehen = 1;
             Richtung = Vector3.forward;

             anim.SetBool("left",true);
             StartCoroutine (ldelay ());
         }
     }
     if (other.CompareTag ("z-")) {
         if (drehen == 2) {
             drehen = 3;
             Richtung = Vector3.back;

             anim.SetBool("left",true);;
             StartCoroutine (ldelay ());
         }
         if (drehen == 4) {
             drehen = 3;
             Richtung = Vector3.back;
     
             anim.SetBool("right",true);
             StartCoroutine (delay ());
         }
     }
     if (other.CompareTag ("x+")) {
         if (drehen == 1) {
             drehen = 2;
             Richtung = Vector3.right;
     
             anim.SetBool("right",true);
             StartCoroutine (delay ());
             Debug.LogWarning("quitted iterator");
         }
         if (drehen == 3) {
             drehen = 2;
             Richtung = Vector3.right;
         
             anim.SetBool("left",true);
             StartCoroutine (ldelay ());
         }
     }
     if (other.CompareTag ("x-")) {
         if (drehen == 1) {
             drehen = 4;
             Richtung = Vector3.left;
         
             anim.SetBool("left",true);
             StartCoroutine (ldelay ());
         }
         if (drehen == 3) {
             drehen = 4;
             Richtung = Vector3.left;
     
             anim.SetBool("right",true);
             StartCoroutine (delay ());
         }
     }
 }
 IEnumerator delay(){
     Debug.LogWarning ("in iterator");
     yield return new WaitForSeconds (1);
     body.velocity = Vector3.zero;
     body.angularVelocity=Vector3.zero;
     yield return new WaitForSeconds (1);
     body.velocity =8*Richtung;
     anim.SetBool ("right", false);
     rotieren = Quaternion.Euler(Richtung*Time.deltaTime);
     }
     IEnumerator ldelay(){
     Debug.LogWarning ("in iterator");
     yield return new WaitForSeconds (1);
     body.velocity = Vector3.zero;
     body.angularVelocity = Vector3.zero;
     yield return new WaitForSeconds (3);
     body.velocity = 8 * Richtung;
     anim.SetBool ("left", false);
     rotieren = Quaternion.Euler(Richtung*Time.deltaTime);
 }

}

4 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by KarlKarl2000 · Sep 01, 2016 at 02:45 PM

@Somniothedreamer

I had the exact same problem.. I found 5.4 did some weird stuff with my

 transform.Translate (Vector3.left * Time.deltaTime) 

I found a nifty solution here:

http://answers.unity3d.com/questions/1078784/transformtranslate-not-working-3.html

Then I hacked it to do what I needed. Hope this makes sense and helps others online.

   void Update()
     {
     if(transform.localScale.x > 0) {
         _move = new Vector3(4,0,0);
     }
     
     if(transform.localScale.x < 0) {
         _move = new Vector3(-4,0,0);
     }
     
     transform.Translate (_move * Time.deltaTime * 50, Space.World);
     }

Sharing is caring

https://madewith.unity.com/profiles/2dos

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 3dmihai · Sep 02, 2016 at 07:16 AM 0
Share

Please explain why exactly are you checking the scale.

avatar image KarlKarl2000 3dmihai · Sep 04, 2016 at 08:43 AM 1
Share

@3dmihai

$$anonymous$$y character is a 2D sprite. So when he's

  • Facing left he's scaled (-1,0,0) Which basically flips him around.

and when

  • Facing right he's scaled (1,0,0) Which flips him the other direction.

OP was asking why the original

    transform.Translate (Vector3.left * Time.deltaTime) 

no longer works in 5.4. This was one way I got it working again for my game. But it depends on how you are using transform.Translate.

Hope this answers your question

Sharing is caring

https://madewith.unity.com/profiles/2dos

avatar image 3dmihai KarlKarl2000 · Sep 06, 2016 at 11:17 AM 0
Share

It does answer my question, thank you very much :)

avatar image
2

Answer by mj321 · Aug 25, 2016 at 04:38 PM

Did you actually attach that script to an object? I tested it and it worked for me.

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 3dmihai · Aug 25, 2016 at 04:56 PM

The script needs to be attached to your robot as a component. Then try modifying the 0.1f multiplier, probably it moves very slowly.

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 Somniothedreamer · Aug 25, 2016 at 05:16 PM

yes id did attached it to two diffrent objects. Maybe i have to change my version of unity. My actual is 5.4.0f3

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 mj321 · Aug 25, 2016 at 05:39 PM 0
Share

That's the same version i use. Also, a trivial script like this should work everywhere. Please try again with a new project, just add one cube and attach the script. Even try creating a new script and just paste that one line into the Update() method. $$anonymous$$aybe you broke something trivial by accident.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Limit movement to just forward/backward and left/right 0 Answers

Moving walls in multiple places 1 Answer

Rigidbody movement instead of transform? 0 Answers

Can someone help me rewriting my script from transform.position to transform.Translate? 1 Answer

How can I move an object between two positions, while it is on a rotating platform? 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