Raycasting and 2D Items

0 favourites
  • 2 posts
From the Asset Store
2d mushroom sprite 2d game character enmy sprite game art
  • Hey!

    Recently I've spent a few hours to implement raycast technique in Construct 3. So I've got a question: is there a way to create items like medkits in doom of ammo in wolf3D? And how do I actually calculate height of the walls? Currently I am using screen.height-ray.width, but is seems like it's curved and weird sometimes

    If anyone got interested, I could pin .c3p file.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hey!

    With my raycasting engines in construct i make it easy for me.

    You will need:

    player ------type: sprite

    ray_angle ---type: sprite

    2d_wall -----type: sprite

    3d_wall -----type: sprite

    2d_sprite ---type: sprite

    3d_sprite ---type: sprite

    CONTAINER(2d_sprite, 3d_sprite)

    Start of layout: for 0-119 create ray_angle at player.x+120 player.y-60+loopindex

    Then, you either pin those points to the player via the behaviour or use the new hierarchy system.

    Then you cast to those sprites and for the height of the "3D" walls you do:

    for each ray_angle raycast....

    To set the height of the "3d_wall" sprite you do:

    120/player.lineofsight.hitdistance/cos(anglediff(player.angle,angle(player.x,player.y,player.lineofsight.hitx,player.lineofsight.hity)))*"something(the size of the 2d walls perhaps)?"

    //Remember to put the origin on the left most side of the "3d_wall" sprite, and in the middle. Just press "4" on the keypad.

    For the 2d sprite you will need 4 variables.

    Cx = player.x - 2d_sprite.x

    Cy = player.y - 2d_sprite.y

    Sprite_angle = angle(0,0,2d_sprite.cx,2d_sprite.cy)-player.angle

    X_pos = 60+tan(sprite_angle)*120 ///Half the screen width, times the full screen width.

    3d_sprite: Set x position to 2d_sprite.x_pos

    The y value you can set on creation or start of layout. 3d_sprite.y = (half the screen height). You can play around with the y value to see if you get any other game ideas...

    3d_sprite height = 120/distance(player.x,player.y,2d_sprite.x,2d_sprite.y)/cos(anglediff(player.angle,angle(player.x,player.y,2d_sprite.x,2d_sprite.y)))*something, (probably same as the height for the "3d" walls)

    If 3d_sprite height is lower than 0, set to 0.

    3d_sprite width = 3d_sprite height. //You can play around with the width, depending on how you draw the billboard sprites.

    Have a good one!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)