- Home /
Question by
rafaelcbarna · Jan 29, 2019 at 05:39 PM ·
scripting problembeginnerjumping object
Make my boss jump on Player position after x seconds
Hello, I've been working on the second boss of my first game, his only ability is jumping on the player position. So far I could only make the boss jump on Y, or make him teleport to the player instead of jumping. Thanks in advance.
public float speed;
public int startingHealth = 4;
public int currentHealth;
public bool bossKilled = false;
public int jumpForce;
public bool playerInRange = false;
private float timeJump = 1f;
private float atimer = 1f;
private bool canJump = false;
private Transform target;
private Rigidbody2D rb;
Animator anim;
Vector2 initialPos;
public bool grounded;
public Transform groundCheck;
public LayerMask layerGround;
public float radiusCheck;
void Start () {
anim = GetComponent<Animator>();
currentHealth = startingHealth;
initialPos = gameObject.transform.position;
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
rb = GetComponent<Rigidbody2D>();
}
void Update () {
grounded = Physics2D.OverlapCircle(groundCheck.position, radiusCheck, layerGround);
if (currentHealth == 0)
{
anim.Play("BossDeath");
bossKilled = true;
return;
}
if (playerInRange)
{
bossAttack();
}
}
private void Awake()
{
instance = this;
}
private void bossAttack()
{
if (timeJump > 0)
{
canJump = false;
timeJump -= atimer * Time.deltaTime;
anim.SetTrigger("Idle");
}
else
{
canJump = true;
timeJump = 5f;
anim.SetTrigger("Jump");
Attacking();
}
}
private void Attacking()
{
if (canJump)
{
if (playerInRange == true && grounded)
{
rb.AddForce(Vector2.up * 1000f);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
does SetResolution() change the resolution in editor game screen??? 1 Answer
How to use a timer with a button 2 Answers
True and false work weird? 1 Answer
OnTriggerEnter and UI Collisions. 0 Answers