Question by
vishnujayaraj128 · Apr 01, 2020 at 06:56 PM ·
shootingreflectionslaser
How to create Ricochet effect
Hi Guys, I would like to create a Ricochet effect for my laser, But it's going up direction after hitting the wall
Canon script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Shot : MonoBehaviour
{
public Slider slider;
[SerializeField]
private float _fireRate = 0.25f;
private float _canFire = 0.0f;
[SerializeField]
private GameObject _laserPrefab;
[SerializeField]
private GameObject _spawnPaoint;
// Start is called before the first frame update
private void Start()
{
}
// Update is called once per frame
private void Update()
{
transform.localEulerAngles = new Vector3(0, 0, slider.value);
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButton(0))
{
shoot();
}
}
private void shoot()
{
if (Time.time > _canFire)
{
//Instantiate(_laserPrefab, transform.position + new Vector3(0, 0.684f, 0), Quaternion.identity);
Instantiate(_laserPrefab, _spawnPaoint.transform.position, transform.rotation);
_canFire = Time.time + _fireRate;
}
}
}
Laser Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Laser : MonoBehaviour
{
[SerializeField]
private float _speed = 10.0f;
private Rigidbody2D _rb;
private Vector3 m_dir;
// Start is called before the first frame update
private void Start()
{
_rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
private void Update()
{
//_rb.velocity = Vector3.up * 40 * Time.deltaTime;
transform.Translate(Vector3.up * _speed * Time.deltaTime);
if (transform.position.y >= 5.53f)
{
if (transform.parent != null)
{
Destroy(transform.parent.gameObject);
}
Destroy(this.gameObject);
}
}
}
laser.gif
(416.8 kB)
Comment
Your answer
Follow this Question
Related Questions
How do I make my ships lasers come out straight 0 Answers
Issue with Dynamic Laser Reflection on Walls 1 Answer
Best way of manage make a real world Shooting Simulator 0 Answers
Problem with Reflecting Laser (RaycastHit2D and Line Renderer) 0 Answers
Deferred Rendering, Command Buffers, and Reflection Probes? 0 Answers