[ad_1]
I’ve a process which i’ve a transferring ship that may shoot in any course i need. i’ve to shoot to standing or transferring close by objects.
the issue is, I can not appropriately calculate true shoot course.I need to discover a course after ship velocity apply on it then bullet go to focus on place.
Ship shoot methodology :
public void shoot(vector3 course)
{
var projectile= new Projectile();
projectile.Velocity = Ship.LinearVelocity + Vector3.Normalize(course) * Ship.GunInfo.ProjectileSpeed;
projectile.Place = Ship.Place;
World.Add(projectile);
}
Projectile replace methodology :
public void Replace(TimeSpan deltaTime)
{
Place+= Velocity * deltaTime;
}
So what’s true course which should to be handed into shoot methodology?
I attempted bellow calculations :
1- first answer i attempted to shoot targets : (actually unhealthy accuracy)
var baseDirection = goal.Place - Ship.Place;
var course = baseDirection - Ship.LinearVelocity/Ship.GunInfo.ProjectileSpeed;
shoot(course);
2- second answer i attempted to shoot targets : (higher accuracy)
var baseDirection = goal.Place - Ship.Place;
var shootDirection = Ship.LinearVelocity + Vector3.Normalize(baseDirection) * Ship.GunInfo.ProjectileSpeed;
var course = Vector3.Replicate(- shootDirection, Vector3.Normalize(baseDirection))
shoot(course);
-
All velocities (ship, projectile) are vector3.
-
I do not use any physic engine however i’ve vector3 math capabilities like (normalize, undertaking, dot, …).
-
Normalize imply vectorA/size(vectorA) meaning vector with size one
-
ship pace at shoot time is fixed however periodically change velocity and course.
-
there is no such thing as a gravity,wind and so on all velocity stay fixed besides ship that change its method.
[ad_2]