- Home /
Rocket jumping - rigid / transform problem
I Have an issue related to the player after getting hit by the rocket and being blasted into the air, when he moves since he uses transform.pos to move and the rocket uses addforce when the player lets go of A or D they do not continue the direction they were going, instead they try to use were the old rockets force leads them to go, this isn't desirable
I did not press A at any point in the video
it was the old rocket jump velocity
Note this issue is a bit wordy to read so I'm going to post a video on what the heck I'm talking about also sorry for the bad everything this was made in less than a week and I barley know unity & the var names are not correctly "cased?"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BombTest : MonoBehaviour
{
public GameObject Explosion;
public float ExpForce;
public float radius;
[SerializeField] LayerMask HitPlayerLayer;
void OnCollisionEnter2D(Collision2D other)
{
Explode();
GameObject Bombins = Instantiate(Explosion, transform.position, transform.rotation);
Destroy(Bombins, 12f);
}
void Explode() {
Collider2D[] objects = Physics2D.OverlapCircleAll(transform.position, radius, HitPlayerLayer);
foreach (Collider2D obj in objects) {
Vector2 Direction = obj.transform.position - transform.position;
obj.GetComponent<Rigidbody2D>().AddForce(Direction * ExpForce);
//same thing as above ^ just not addforce - there Could?? be a diffrence
//obj.GetComponent<Rigidbody2D>().transform.position = obj.GetComponent<Rigidbody2D>().position + (Direction * ExpForce);
}
}
Your answer
Follow this Question
Related Questions
How to make RigidBody's movement using fixed movement/velocity and other forces all together? 3 Answers
Erratics movements from my rigidbody : why does it behave like that? 0 Answers
I do you control movements and apply other forces at the same time ? 0 Answers
Correct player position when moving between scenes. 1 Answer