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 Danao · Nov 16, 2014 at 08:02 AM · movementtransformpositionlogic

How can I call this player transform.position code once, then stop?

Hi all, I am using the following code to move my player to the check point (after death, if the check point is cleared). That works fine, but then the player is stuck at the check point transform position. Any suggestions on how to get my player moving freely again after moving to the check point? Thanks!

  void  Start (){
                     
             if (checkPoint >= 1) {
                 gameObject.transform.position = currentCheckPoint.transform.position;
                 }
             } 
 
 And...
 
     public class CheckPointScript : MonoBehaviour {
     
         void OnCollisionEnter2D(Collision2D collision) {
     
             if (collision.gameObject.tag == "Player"){
             MainScript myPlayer = (MainScript) GameObject.Find("Player").GetComponent("MainScript");
             myPlayer.currentCheckPoint.transform.position = this.transform.position;
             }
     }
     }


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

2 Replies

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

Answer by blueLED · Dec 11, 2014 at 03:08 AM

I think what you need to do is disable the checkpoint after the player has re-spawned. Because right now, it looks like when the player touches the checkpoint he is being constantly reset to the checkpoint position. So just turn off the checkpoint once it's been touched by the player?

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 Danao · Dec 11, 2014 at 01:31 PM 0
Share

Thanks blueLED. I set the game object to false which seems to take care of the constant position reset. I still wanted to have the checkpoint visible, so I put another sprite behind the original checkpoint game object. Add an animation and I should be good to go :)

avatar image
0

Answer by Jason-H · Nov 16, 2014 at 10:18 AM

Have you got anything checking whether your character should be able to move or not? Maybe you declare the character as unmovable once they die and you're not changing that back upon respawn?

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 Danao · Nov 16, 2014 at 01:16 PM 0
Share

Thanks Jason H. The player can move, but seems restrained to the location of the checkpoint transform (and only sometimes). I'm not sure what is causing the inconsistent results and therefore how I can go about fixing them. Anybody have any suggestions?

avatar image MrSoad · Nov 30, 2014 at 03:37 PM 0
Share

It could be because you have a logic issue where you keep on setting the player position to the ckeckpoint position, so it looks like it has snagged. Put a debug log statement next to any player re-position code and see if that is being called constantly, if so that is what you need to stop/change :)

avatar image Danao · Dec 07, 2014 at 12:11 AM 0
Share

Thanks for the comment $$anonymous$$rSoad. It does seem to call repeatedly which could very well be causing my problem. Any advice on how to get it to stop calling considering my posted code? And sorry for the delay in my reply...work issues as well :D

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

27 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

Related Questions

Getting Camera to Stop Following Player 1 Answer

make player move in direction it's facing 2 Answers

Add specific movement on double click 1 Answer

How to make object follow touch position?Pls Help 0 Answers

How to smooth movement object in one-axis? 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