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 /
avatar image
0
Question by glogloglik · Dec 22, 2015 at 03:14 PM · movementgameobjecttransformmovetranslate

GameObject doesn't move

Hey guys,

I have a 2D game about landing with a spaceship. My spaceship has rigidbody, but I disabled gravity and I'm moving the ship towards the surface using transform.Translate. But the problem is, when I land on the ground, I want to move the player to the left. But nothing seems to work and I really don't have any idea why..

Any help would be appreciated :]

     void Update () {
             player.transform.Translate(0,-gravityForce + speed,0);    
     //my simulaion of gravity
     
             if(Input.GetKey(KeyCode.Space)){
                 fuel -= 1f;
                 speed += 0.001f;
                 Instantiate(smoke, smokeEnd.transform.position, smokeEnd.transform.rotation);
             } else {
                 speed -= 0.001f;
             }
             
             if ((player.transform.position.y < -2f)){              //landed on ground
                 if((speed <= upBoundary)&&(speed >= downBoundary)){    
                     speed = 0;
                     gravityForce = 0;    
                     onGround = true;
                 } else {
                     Crash();
                     onGround = true;
                 }
             }
         }
     
         void FixedUpdate(){
             if (onGround){
 //debug here works fine
                 player.transform.Translate(new Vector3(-2f,0,0));   
             }
         }
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 Vice_Versa · Dec 22, 2015 at 03:21 PM 0
Share

Does your first Translate Function work? and for the transform.translate at the bottom, multiply your Vector3 by Time.deltaTime

avatar image glogloglik Vice_Versa · Dec 22, 2015 at 03:30 PM 0
Share

Yeah, the first one works just fine. Even after multiplying the bottom Vector3 it still doesn't work..

avatar image glogloglik glogloglik · Dec 22, 2015 at 03:41 PM 0
Share

But this is my Crash() function, which I call and where I also move my player, could it somehow interfere?

     void Crash(){
         player.transform.position = new Vector3(0,-2,0);
         player.GetComponent<SpriteRenderer>().sprite = crashedSprite;        
         oops.SetActive(true);
         GUItimer++;
         if(GUItimer >= 100){
             oops.SetActive(false);
             playAgain.SetActive(true);
         }
     }



1 Reply

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

Answer by Zoelovezle · Dec 23, 2015 at 12:23 AM

Make your body Kinematic for creating your own Physics.Since Kinematics will be true , no collision will affect the your player.Use RaycastHit2D for detecting specific platforms and moving over them.

Read the following documentation: http://docs.unity3d.com/Manual/class-Rigidbody2D.html

Watch the following video: http://unity3d.com/learn/tutorials/modules/beginner/physics/raycasting?playlist=17120

Comment
Add comment · Show 2 · 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 glogloglik · Dec 23, 2015 at 08:15 PM 0
Share

Ok it works now, altough I am not really sure why. I had some issues with ray casting so I didn't add that, but it seems it works now bcs I replaced rigidbody with rigidbody2d with Is$$anonymous$$inematic selected.

avatar image Zoelovezle glogloglik · Dec 24, 2015 at 02:45 AM 0
Share

<333 :) Glad it helped

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

38 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

Related Questions

GameObject not looking at me.. 1 Answer

How can I stop a gameobject movement with timer? 0 Answers

Object cordinates changing when game start 1 Answer

move one object to defined point according to another object movement to that point 0 Answers

transform.translate limits 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