Hey guys
Anyone have any ideas of a way I can have my turret make a educated guess where a ship might be judging by the direction its flying? So maybe like a future forward motion guess.
Hey guys
Anyone have any ideas of a way I can have my turret make a educated guess where a ship might be judging by the direction its flying? So maybe like a future forward motion guess.
Future position = current position + velocity * time
You could do something like this:
probableFuturePosition = ship.transform.forward * shipspeed;
Thanks for the reply abnu. I didn’t know I could do math on forward like that. I’ll try that out.
Right now im using
Quaternion targetlook = Quaternion.LookRotation(TargetTransformPosition - MuzzleTransformPosition);
and then
this.transform.rotation = Quaternion.Lerp(this.transform.rotation,targetlook,Time.deltaTime * 10000);
So I guess my issue is I need the turret to turn and point at the future location
oh wait I think I just need to give Lookrotation
ship.transform.forward * shipspeed
ya that idea is incorrect lol. that just gave the turret which way I was looking
Which one? :)An even Simpler way would be to add an empty child to the ship called futurePosition and put it as far ahead of the ship as you want. Then put a script like this on the turret
public Transform target;
void Update()
{
transform.LookAt(target);
}
and drag the futurePosition into the Transform slot.
if your ship doesn’t have a constant speed:
public float offset =3f;
void Update()
{
transform.localPosition = new Vector3(0, 0,offset );
}
on the futurePosition GameObject and then vary offset according to the speed of your ship
That is an awesome idea Abnu
Not sure that is going to work though. Been thinking about it for a while.
I use a raycast to double check to make sure the ship is viewable before the turret fires.
So Ive been trying to think of a way to still do that.
One idea is give the transform that is placed ahead of the ship a box collider but then the collider would hit stuff. I notice if I use ignore collision by layer on stuff raycast stops working as well.
So now I have another dead end again.
Do you have any ideas on this by chance?
Really appreciate the help so far btw
Actually I just thought of something
Instead of raycasting making sure I fire at something I want the turet to fire at. I’ll just have it check things not to fire at. This way the ray cast doesn’t have to hit the ship.
Going to to see if that all works then. Think it will all be ok after doing that change.
you could do that as well
void OnBecameVisible()
{
shootable = true;
}
void OnBecameInvisible() {
shootable = false;
}
and then check shootable from the turret
Or if You just want to hit moving target, here is geat code I just found for my turrets:
http://danikgames.com/blog/moving-target-intercept-in-3d/
It solved my prediction problem.
Thanks Karwoch I’ll check that out. I got abnu idea working great with placing a transform ahead of the ship and changing its distance from the ship according to the ships speed.
Thanks a lot Abnu
The little difference - with this scirpt I only put speed of my target, my position, target position, and velocity of my projectile and it works! Hits directly every time even on 6km range Now I only need to add to this velocity of my ship, but I guess simply adding my speed to speed of my target should solve this problem with same function.