Hello!
I’m building a game and I’m wondering how to place bomb at a current character location, I tried everything but nothing seems to work.
Here’s the code of the movement script and setup a bomb…
The bomb always ends up in (0,0,0) ![]()
public class PlayerMovements : MonoBehaviour{
// Normal Movements Variables
private float walkSpeed;
private float curSpeed;
private float sprintSpeed;
private float maxSpeed;
public Vector2 currentDirection = Vector2.zero;
private CharacterStat plStat;
void Start()
{
plStat = GetComponent<CharacterStat>();
walkSpeed = (float)(plStat.Speed + (plStat.Agility/5));
sprintSpeed = walkSpeed + (walkSpeed / 2);
}
void FixedUpdate()
{
curSpeed = walkSpeed;
maxSpeed = curSpeed;
// Move senteces
rigidbody2D.velocity = new Vector2(Mathf.Lerp(0, Input.GetAxis("Horizontal")* curSpeed, 0.8f),
Mathf.Lerp(0, Input.GetAxis("Vertical")* curSpeed, 0.8f));
}
}
And the set a bomb…
public class PlaceBomb : MonoBehaviour {
public GameObject Bomba;
public GameObject Character;
void SetBomb ()
{
Instantiate(Bomba, new Vector3(Character.transform.position.x,Character.transform.position.y,0) , Quaternion.identity);
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetButtonDown("Fire1")) {
SetBomb();
}
}
}