SOLVED: How do enemies aim shots in 3D?

0 favourites
  • 6 posts
From the Asset Store
A sound pack containing 132 laser gun sound effects, including mono and stereo versions of audio files.
  • We all pretty much know how to use angle() so a shot can be aimed from one object to the angle of another, but how do you throw the Z coordinate into the mix if you're doing a first person game? Like the 3D platformer example.

    The specific formula I ended up with is

    atan((Target.ZElevation - Self.ZElevation) / distance(Self.X, Self.Y, Target.X, Target.Y))

  • Use the tangent of the (z) viewing angle multiplied by any given distance to get the height at that distance.

    tan(zAngle)*distance(self.x,self.y,target.x,target.y) = zHeight at target.x/y

  • Are you talking about the 3D camera with viewing angle? Because I need an enemy to aim at the player.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you already know the height of both the enemy and the player, you could use a simple lerp to get the hight of any point in between them. Lerp(a,b,x) where a and b are the height of the two known objects and x is the progress of the projectile between them, from 0 to 1.

  • I think I don't know how to explain what I'm having trouble with because that doesn't work either. In the video below I'm trying to get the boomerang to set its Z movement angle to the player throughout its entire return flight so it will home in on the player at the correct speed. If I can get this to work right then anything should be able to accurately aim at something in Z elevation.

    It's using bullet behavior as well as a zAngle variable I made that alters its bullet speed so it moves the correct speed if aimed higher or lower. As you can see, the math is correct to change its movement based on zAngle as I can aim directly at the center of my vision no matter where I fire. The problem is that I set the zAngle to -3DCamera.CameraYRotation + 90 when the player fires to accomplish this, but I have no idea how to input something other than -3DCamera.CameraYRotation + 90 or a specific number which makes things like homing shots impossible until I know how. Thanks so far for the help though.

    Here's a video attempting to show what I've done so far.

    https://drive.google.com/open?id=1QurGjbN8Sn4EHbXZsv349R8_Ez19POBY&authuser=ummagummabur%40gmail.com&usp=drive_fs

    EDIT: I found a diagram of the value I need to caclulate. It's X in this. Sorry if I'm being dense. This is actually the first time I've done anything in 3D. So I probably am like one of those 2D creatures in flatland coming into 3D. lol

  • OMG thank you. You helped me find the proper terms so I could look up the formula and recreate it verbatim in C3 and then change it to suit my needs. Marking as solved. My school system utterly failed me, so I've had to learn what should be simple things like sine and cosine as an adult.

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