Question by
auliamnaufal · Dec 15, 2020 at 10:07 PM ·
unity 52d2d-platformerplatformer
why when the player position changed, the player get stuck in that positon,Why when i change the Player position to an object, the player get stuck
i want to make the player position changed when the popupindex is 3 and when the popupindex is 3 the player does change the position but the player stuck to that position, the player already have a rigidbody and the let's say "spawner' does not, i tried this code before on a another implementation and it works fine.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class tutorialManager : MonoBehaviour
{
public GameObject[] popUps;
private int popUpIndex;
public GameObject Enemy;
public GameObject Healthbar;
public GameObject trapStart;
public GameObject Player;
int currenthealth;
private void Start()
{
Healthbar.SetActive(false);
}
// Update is called once per frame
void Update()
{
for (int i = 0; i < popUps.Length; i++)
{
if (i == popUpIndex)
{
popUps[i].SetActive(true);
}
else
{
popUps[i].SetActive(false);
}
}
if (popUpIndex == 0)
{
if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.A))
{
popUpIndex++;
}
}
else if (popUpIndex == 1)
{
if (Input.GetKeyDown(KeyCode.Space))
{
popUpIndex++;
}
}
else if (popUpIndex == 2)
{
Enemy.SetActive(true);
if (Enemy.GetComponent<Enemy>().currentHealth <= 0)
{
popUpIndex++;
}
} else if (popUpIndex == 3)
{
Player.transform.position = Player.GetComponent<HealthBar>().Checkpoint;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Having a couple of problems regarding 2D Movement. 1 Answer
Teleport 2D Character on TriggerEnter 2 Answers
Platformer 2D 1 Answer
Enemy AI ignores the distance from the player 0 Answers
Trouble with directing launched projectiles in Unity 2D 0 Answers