Sign in to follow this  

Collision point of 2 curves in a 3d-room

This topic is 2541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i am programming a small game for quite some time. We started coding a small FPS-Shooter inside of a project at school to get a bit experience using directX. I dont know why, but i couldnt stop the project and started programming at home aswell. At the moment i am trying to create some small AI. Of cause thats definatlly not easy, but thats my personal goal anyways. The topic could prolly fill multiple books hehe. I've got the walking part of my bots done so far. They walk along a scriped path. I am not working on the "aiming" of the bots. While programming that i hit on some math problem i couldnt solve yet. I hope of your input on this to help me get further. Concepts, ideas and everything else are highly appreciated.

Problem: Calculate the position (D3DXVECTOR3) where the curve of the projectile (depends on gravity, speed), hit the curved of the enemys walking path (depends on speed). We assume that the enemy walks in a constant line.

Known variables:

float projectilSpeed = 2000 m/s //speed of the projectile per second
float gravitation = 9.81 m/s^2 //of cause the gravity lol
D3DXVECTOR3 targetPosition //position of the target stored in a vector (x,y,z)
D3DXVECTOR3 projectilePosition //position of the projectile
D3DXVECTOR3 targetSpeed //stores the change of the targets position in the last second


ProjectilePosition at time of collision = ProjectilePos_t
TargetPosition at time of collision = TargetPos_t
ProjectilePosition at time 0, now = ProjectilePos_0
TargetPosition at time 0, now = TargetPos_0
Time to impact = t
Aim-angle = theta

My try: Found a formular to calculate "drop" (Drop of the projectile based on the gravity) on Wikipedia:

float drop = 0.5f * gravity * t * t

The speed of the projectile has a horizontal and a vertical part.. Found a formular for that on wikipedia aswell:

ProjectilVelocity.x = projectilSpeed * cos(theta)
ProjectilVelocity.y = projectilSpeed * sin(theta)

So i would assume this is true for the projectile curve:

ProjectilePos_t.x = ProjectilePos_0.x + ProjectileSpeed * t
ProjectilePos_t.y = ProjectilePos_0.y + ProjectileSpeed * t + 0.5f * gravity * t * t
ProjectilePos_t.z = ProjectilePos_0.z + ProjectileSpeed * t

The target walk with a constant speed, so we can determine his curve by this:

TargetPos_t = TargetPos_0 + TargetSpeed * D3DXVECTOR3(t, t, t)

Now i dont know how to continue. I have to solve it somehow to get a hold on the time to impact somehow. As a basic formular i could use:

float time = distanz / projectileSpeed

But that wouldnt be truly correct as it would assume a linear "Trajectory". We just find this behaivor when using a rocket.

I hope i was able to explain the problem as much as possible. If there are questions left, feel free to ask me!

Greets from germany, Frank

The main problem is that i cant calculate the enemies position at collision time as i dont have the time passed until the collision occurs.. And on the other hand i cant calculate the time without knowing the enemies location at impact time. Maybe an iterative method solves this.

curve enemy:
pos(t).x = pos(0).x + speed.x * time
pos(t).y = pos(0).y + speed.y * time
pos(t).z = pos(0).z + speed.z * time

curve projectile:
pos(t).y = pos(0).y + sin(theta) * speed + 0.5 * gravity * time * time

pos(t).x and pos(t).z not sure how to calculate in (x and z) define the forward direction basically.. not just x.. cant calculate the enemy without knowing the time.. and i cant calculate the time without knowing the angles (theta, pitch/yaw) and the distance it will be

Share this post

Link to post
Share on other sites
Maybe you should try to cut this problem down on static intersections.
The trajectory of your bullet consists of small straight lines.
I suppose your target is a hitbox.
Now you have the current position of the target and the current small line,
that starts at the old bullet position and ends at the new bullet position.
Now you only try wether the line and the hitbox intersect.
This problem should be solvable and its only limitation lies in the size of the steps.
I hope I pointed you in the right direction to find a solution for your problem.

Share this post

Link to post
Share on other sites

This topic is 2541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this