Jump to content

Throw 3D of bullet


Ethernet

Recommended Posts

Hello. I trying to make 3D throw for my bullet script. On X and Y axis is okay, but idk how to calculate Z axis. This script should work like this:

rZz3aPa.png

But works like this:

U3ZYguD.png

My code:
 

        x = x - math.sin ( math.rad ( rotationZ ) ) * 0.1
        y = y + math.cos ( math.rad ( rotationZ ) ) * 0.1

        --x1 = x- math.sin ( math.rad ( rotationZ ) ) * 4
        --y1 = y + math.cos ( math.rad ( rotationZ ) ) * 4

        z = ?

What calculations I must use on Z axis? Thanks!

Edited by Ethernet
Link to comment
  • Discord Moderators

You need more than just rotationZ to do that, if you want to find a point from the rotation of the gun. 

Assuming your weapon has a pitch and yaw, and roll is 0, you would do this to find your point, where yaw is your rotationZ (in radians)

x = x + 0.1 * math.cos(pitch) * math.cos(yaw)
y = y + 0.1 * math.cos(pitch) * math.sin(yaw)
z = z + 0.1 * math.sin(pitch)

 

Link to comment

Okay, thanks Zango, but what's pitch?

On 23/10/2019 at 20:33, Zango said:

You need more than just rotationZ to do that, if you want to find a point from the rotation of the gun. 

Assuming your weapon has a pitch and yaw, and roll is 0, you would do this to find your point, where yaw is your rotationZ (in radians)


x = x + 0.1 * math.cos(pitch) * math.cos(yaw)
y = y + 0.1 * math.cos(pitch) * math.sin(yaw)
z = z + 0.1 * math.sin(pitch)

 

 

Link to comment
  • Discord Moderators

It's the angle your gun is tilted upwards in your picture. Like this

rx, ry, rz = getElementRotation(gun)
rx = math.rad(rx)
rz = math.rad(rz)

x = x + 0.1 * math.cos(rx) * math.cos(rz)
y = y + 0.1 * math.cos(rx) * math.sin(rz)
z = z + 0.1 * math.sin(rx)

What is your gun, is it an object or a custom weapon? It might be better for you to use a matrix, see the example in getElementMatrix

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...