Raycasting Problem

Started by Argus Obsidian on Wed, 08/05/2020 - 19:57

Topic category: Help with modding (Java Edition)

Last seen on 23:05, 16. Jun 2021
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Raycasting Problem
Wed, 08/05/2020 - 19:57

I am working on adding guns to my mod, and the best solution I came up with for making them would be to raycast once the gun item is right clicked, and check what mob or block is hit. I prefer not to use a ranged item, as that makes certain parts of my mod impossible to do. Does anyone know how I could achieve this effect?

Last seen on 23:05, 16. Jun 2021
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I have solved this through…
Fri, 08/07/2020 - 21:32

I have solved this through doing a LOT of coding! If anyone else wants to know how to do this, just reply to this post and I will try to explain.

Last seen on 08:22, 14. May 2021
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I'd love to know how you did…
Mon, 08/10/2020 - 13:24

I'd love to know how you did this!

Last seen on 08:39, 19. Nov 2020
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Same!
Thu, 08/13/2020 - 06:38

Same!

Last seen on 16:48, 17. Dec 2020
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
How did you do it?
Sun, 09/06/2020 - 14:19

How did you do it?

Last seen on 23:05, 16. Jun 2021
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Sorry for replying late, but…
Wed, 09/09/2020 - 22:36

Sorry for replying late, but the way I solved this was using a lot of code, not procedures. Simply, every time the player right clicked with a gun, I would run a loop that moved a collision box through space until it collided with something. To make sure the game wouldn't crash, I made it have a maximum shooting distance, but it seems to work very well now.

TLDR: I shot a mob out of the gun. :p

Last seen on 08:39, 19. Nov 2020
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
.......
Thu, 09/10/2020 - 08:05

.......

Last seen on 23:05, 16. Jun 2021
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
A bit more detailed…
Thu, 09/10/2020 - 15:49

A bit more detailed explanation here:

1. I made a gun item that would trigger a procedure when it was right clicked.

2. I edited the code of the procedure, with the built in code editor in MCreator

3. I made it so when triggered, the code would create a bounding box, and using a loop, move it in the direction the player was looking.

4. If the bounding box hit a mob, block, or went too far, it would trigger an action, such as damaging the hit mob or spawning impact particles on the block it struck.

I basically made a lazar gun, because the gun shoots in a perfectly straight line.

Last seen on 18:04, 16. May 2021
Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Can you do a tutorial on…
Fri, 11/27/2020 - 14:43

Can you do a tutorial on this?
You've already created a tutorial on custom animated mobs and that was pretty helpful