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 ztg5 · Feb 10, 2017 at 07:06 PM · c#endless runner

problem in my endless runner

I have made an endless runner game and have been testing it on mobile. The player moves across the screen automatically and then you hold down the screen to move the player up in the air. After i hold down the screen to move the character up the movement of the screen and the player goes slower, and then after letting go the character lurches forward. This is the code i use to make the character to move up, I have no clue if this is the problem but here it is. if (Input.touchCount > 0 && jetPackFuel >= 0.001f) note: i am working in C# This is the script i used to make the camera follow the player

 public class Camera_follow : MonoBehaviour
 {
 
     private GameObject player;
     public float cameraSpeed = 5.0f;
 
     // Use this for initialization
     void Start()
     {
         player = GameObject.FindGameObjectWithTag("Player");
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         if (GameUnit.gameIsPlaying == true)
         {
             //X positon follow
             Vector3 camPos = transform.position;
             camPos.x = player.transform.position.x + 8.0f;
             transform.position = Vector3.Lerp(transform.position, camPos, 3 * Time.fixedDeltaTime);
 
             //y position follow
             camPos.y = player.transform.position.y + 2;
             transform.position = Vector3.Lerp(transform.position, camPos, 2.0f * Time.fixedDeltaTime);
         }
         else {
             Vector3 deathCamPos = transform.position;
             deathCamPos.x = player.transform.position.x;
             transform.position = Vector3.Lerp (transform.position, deathCamPos, 2.0f * Time.fixedDeltaTime);
         }
     }
 }


And then is the code i used to make the character move forward

 public class Player_move : MonoBehaviour {
     public static int playerSpeed = 10;
     void FixedUpdate()
     {
         gameObject.transform.Translate(Vector3.right * playerSpeed * Time.fixedDeltaTime);
     }
 }

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 HenryStrattonFW · Feb 10, 2017 at 09:15 PM 0
Share

There is no way anyone will be able to help with that tiny portion of code, we need to see the whole script controlling your character in order to work out what might be the cause of your issue.

avatar image ztg5 · Feb 10, 2017 at 09:20 PM 0
Share

This is the player move script. : public class Player_move : $$anonymous$$onoBehaviour { public static int playerSpeed = 10; void FixedUpdate() { gameObject.transform.Translate(Vector3.right playerSpeed Time.fixedDeltaTime); } }

This is the camera follow script: public class Camera_follow : $$anonymous$$onoBehaviour {

private GameObject player; public float cameraSpeed = 5.0f; // Use this for initialization void Start() { player = GameObject.FindGameObjectWithTag("Player"); } // Update is called once per frame void FixedUpdate() { if (GameUnit.gameIsPlaying == true) { //X positon follow Vector3 camPos = transform.position; camPos.x = player.transform.position.x + 8.0f; transform.position = Vector3.Lerp(transform.position, camPos, 3 Time.fixedDeltaTime); //y position follow camPos.y = player.transform.position.y + 2; transform.position = Vector3.Lerp(transform.position, camPos, 2.0f Time.fixedDeltaTime); } else { Vector3 deathCamPos = transform.position; deathCamPos.x = player.transform.position.x; transform.position = Vector3.Lerp (transform.position, deathCamPos, 2.0f * Time.fixedDeltaTime); } }

Sorry about that @HenryStrattonFW

avatar image HenryStrattonFW ztg5 · Feb 10, 2017 at 09:55 PM 0
Share

Not sure, I can't see anything that would immediately look wrong to me at first glance (although it is odd to be doing non-physics-based movement from FixedUpdate ins$$anonymous$$d of Update but Not sure that it would cause a problem).

I'd advise posting the code as part of your question (you can edit the question, when posting the code, please use the code format button with the 1's and zero's to make it easier for people to read) hopefully someone else will be able to see what I'm missing, or have another idea.

Also worth posting all of the code, I'm noticing the code you iniitialy mentioned regarding the touch input did not appear in any of the code you then posted.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ztg5 · Feb 10, 2017 at 09:18 PM

This is the player move script. : public class Player_move : MonoBehaviour { public static int playerSpeed = 10; void FixedUpdate() { gameObject.transform.Translate(Vector3.right playerSpeed Time.fixedDeltaTime); } }

This is the camera follow script: public class Camera_follow : MonoBehaviour {

 private GameObject player;
 public float cameraSpeed = 5.0f;

 // Use this for initialization
 void Start()
 {
     player = GameObject.FindGameObjectWithTag("Player");
 }

 // Update is called once per frame
 void FixedUpdate()
 {
     if (GameUnit.gameIsPlaying == true)
     {
         //X positon follow
         Vector3 camPos = transform.position;
         camPos.x = player.transform.position.x + 8.0f;
         transform.position = Vector3.Lerp(transform.position, camPos, 3 * Time.fixedDeltaTime);

         //y position follow
         camPos.y = player.transform.position.y + 2;
         transform.position = Vector3.Lerp(transform.position, camPos, 2.0f * Time.fixedDeltaTime);
     }
     else {
         Vector3 deathCamPos = transform.position;
         deathCamPos.x = player.transform.position.x;
         transform.position = Vector3.Lerp (transform.position, deathCamPos, 2.0f * Time.fixedDeltaTime);
     }
 }

}

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

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

8 People are following this question.

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

Related Questions

System Equipment and Changing Clothes in 2d Endless Runner Game ? 0 Answers

I am trying to offset the camera from the player at all times even if the player moves. 0 Answers

Moving left and right with one button in 2d Game 1 Answer

need help in making an object pooler 1 Answer

Endless runner spawing platform spawns too many and too far apart. Help with code please? 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