Question by
Rafones12 · May 14, 2020 at 12:59 PM ·
scripting problemforcetriggersfindobjectoftype
Donkey Kong keg eject
Im trying to do the same as donkey kong game. At the moment, my object enter on the keg, but i cannot aplly force to "eject" the object from keg. What im doing wrong?
public class Keg : MonoBehaviour
{
public float zPos;
public Rigidbody2D rb;
public bool foxIn;
public FoxOnKeg foxOnKegScript;
private float force = 50f;
void Start()
{
foxIn = false;
rb = GetComponent<Rigidbody2D>();
foxOnKegScript = GameObject.Find("Raposa").GetComponent<FoxOnKeg>();
}
public void FixedUpdate()
{
if (foxIn)
{
zPos--;
}
}
public void OnCollisionStay2D(Collision2D other)
{
var keyboard = Keyboard.current;
if (other.gameObject.CompareTag("Player"))
{
foxIn = true;
other.transform.SetParent(transform);
other.gameObject.transform.position = new Vector2(transform.position.x, transform.position.y);
transform.eulerAngles = Vector3.forward * zPos;
if (keyboard.bKey.wasPressedThisFrame && foxIn == true)
{
other.rigidbody.velocity = transform.up * force;
//rb.velocity = transform.up * force;
}
}
}
public void OnCollisionExit2D(Collision2D other)
{
if (other.gameObject.CompareTag("Player"))
{
foxIn = false;
zPos = 0f;
other.transform.SetParent(null);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Why isn't AddExplosionForce working? 1 Answer
AudioSource dissappears in variable window on Play 2 Answers
Increase jump speed colliding on a box ?? 1 Answer
Call function when prefab is collided 1 Answer
Any other object in trigger 1 Answer