How do I get a bullet to fire center screen in 3d?

0 favourites
  • 11 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • This is the closest I can come to getting a projectile to fire straight in a 3-d world, any suggestions?

  • construct.net/en/forum/construct-3/how-do-i-8/set-bullet-angle-axis-166554

    I replied there to someone else, you prob should use zelevation to make bullet appear flying forward.

  • I don't find what your suggesting to make sense. Zelevation controls the ALTITUDE of an object viewed with a 3-d camera, it only controls depth if you are in 2-d. So if you are suggesting that we use a 2-d (HUD ATTACHED) bullet then it would literally move with the screen and not be inside the game world.

    The only way is to assign a Zelevation per tick based on CameraYRotation to keep it center screen, which after a few tries reveals itself as being a ratio of speed to Zelevation as a bullet fired straight up isn't going anywhere x/y wise.

    I would love to hear an improvement on my formula or a further explanation if I am misinterpreting your suggestion but it sounds like your taking a guess at it and about 15 steps behind the trial and error ladder I am on.

  • I don't find what your suggesting to make sense. Zelevation controls the ALTITUDE of an object viewed with a 3-d camera, it only controls depth if you are in 2-d. So if you are suggesting that we use a 2-d (HUD ATTACHED) bullet then it would literally move with the screen and not be inside the game world.

    The only way is to assign a Zelevation per tick based on CameraYRotation to keep it center screen, which after a few tries reveals itself as being a ratio of speed to Zelevation as a bullet fired straight up isn't going anywhere x/y wise.

    I would love to hear an improvement on my formula or a further explanation if I am misinterpreting your suggestion but it sounds like your taking a guess at it and about 15 steps behind the trial and error ladder I am on.

    I was taking a guess, since what you are trying to do is preatty advanced. But i can be wrong, might be very easy to, wait for another reply.

  • Here’s one way. Give your bullet sprite three variables: vx,vy,vz.

    Then add events like this:

    on click 
    -- create bullet at (camera.x,camera.y) 
    -- bullet: set zelevation to camera.z 
    -- bullet: set vx to camera.forwardx*200 
    -- bullet: set vy to camera.forwardy*200 
    -- bullet: set vz to camera.forwardz*200 
     
    every tick 
    -- bullet: set x to self.x+self.vx*dt 
    -- bullet: set y to self.y+self.vy*dt 
    -- bullet: set zelevation to self.zelevation+self.vz*dt

    That would shoot a bullet in a straight line from the camera with a speed of 200.

    The only thing I’m unsure of is how c3 does zelevation values. They initially made it 0 to 100 so you may need to scale the z stuff by some value.

  • Thanks r0j0hound, I haven't thought of trying it that way. Also sorry sami if I sounded frustrated thanks for replying too!

    Update: 3DCamera.Forward properties don't seem to work for me

    These values are always the same no matter what I do with the camera

    3DCamera.ForwardX = 1

    3DCamera.ForwardY = 0

    3DCamera.ForwardZ = 0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well that’s no good if they are always the same value. 3D in c3 seems broken and incomplete.

    Maybe those values get set when you use lookAt and not when you set the camera angle?

    If the forward expressions can’t be relied on then maybe you can calculate them manually from the expressions that do?

    I’m hoping the camera xyz expressions do work. Then maybe there is an expression to convert a screen location to a position in 3D space? Then you’d subtract the camera position from that point and divide it by the distance between the points to get your own forward vector. I honestly am not sure if there is and expression that gives a 3D position from the screen though.

    Another idea is the build a 3x3 matrix of the cameras orientation manually with the same info you feed into the 3Dcamera object. Seems labor intensive though. Or maybe the js api provides more access the stuff in the 3Dcamera.

    Anyways, just some ideas. I unfortunately don’t have the time to try the ideas or see if I’m missing something obvious.

  • I think this is roughly new territory we are in for c3, but I have some ideas and am going to be trying to figure out more. It mentions that some of these 3dCamera properties return "3d unit vectors" which may be referring to some unique value like a string of multiple numbers. I am going to have to test that soon.

  • The expressions forward, up and I think right (or it may be left) are indeed unit vectors. Aka. If you measure their length it will be 1.

    Anyways, from what you said about forward being (1,0,0) makes me think it’s broken. It should give different values depending on the camera orientation.

    Or maybe forward, right and up were mixed up. Just spitballing here based on your testing results. I haven’t tested anything.

  • Ok, so if the up, right and forward expressions are bugged. However the look expressions work. You can subtract the camera position from the look expressions, normalize it to have a magnitude of 1, and use that to be able to shoot forward.

    Anyways, here is an example.

    dropbox.com/s/7fz4uff391at3ms/shoot_forward_3d.c3p

    You can probably discard all the camera related stuff, and just use whatever you already use. It was just for the test.

    Also, I don't think you'll want to be using a sprite for bullets as they aren't always aligned to the view.

  • Way to go R0jOhound! That is the straightest bullet Solution I have seen yet, thanks. This provides a nice platform for me to build a first person accuracy mechanics and have it truthfully provide the center of the cone! :D

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