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);
}
}
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.
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
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.
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);
}
}
}
Your answer
Follow this Question
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