Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Making a 2D projectile bounce off walls?

Asked by
OBenjOne 190
5 years ago

I have a simple game where the player controls a tank in a nearly completely two dimensional map. I had the firing to where I could shoot a bullet to my mouse pointer but I wanted to have it bounce off walls I know how to do the actual bounce by changing the direction the bullet is moving but I can't quite figure out which way to deflect the bullet. I thought about having the bullet move in the three (or 7 if I use and 45 degree angled walls) other directions and then check if it is inside the part it hit but that feels like it would cause unessisary lag and be overly complicated. Is there a way to do this based on the wall's surface? I'm not asking for a script as it probably wouldn't fit with my one anyway. I just need some pointers or a link to look into. Any help is much appreciated.

1 answer

Log in to vote
1
Answered by
SmartNode 383 Moderation Voter
5 years ago
Edited 5 years ago

I am assuming your making something like Noob Simulator, it looks 2D but realistically it’s 3D. Simple, just use raycasting and a formula to reflect it.

Here’s a bug head start if you have no idea where to: guide here

This should help you reflect your raycasts.

However if you think you don’t need to do this, you can simply use the raycast as a path/guide for the missile to travel on. At a certain speed of course.

0
thanks! sorry for the really late reply :/ OBenjOne 190 — 5y
0
No worries man, as long as you get help you don't even need to accept my answer! SmartNode 383 — 5y
Ad

Answer this question