Facing the target

Greetings! I have a problem with my traps . While my knifes that have to face towards to my player like with transform.lookat(myvariable); and my knife just stand there and rotate by facing to the player position so after sometime it will instantiate and i can use addforce later to damage player when collide with knife but when i use lookat function then when game starts the knife stands with 90 degrees of anger and does no even face on it(I think there must something other to face the knife to player) and knife just stand there with a 90 degrees angel upwards . Please help me to solve this .

Images Attached Before runtime and After Runtime :-


I believe this was resolved in the IRC.

Namely, putting the LookAt script on the Knife rather than Knife1 (Which should be used just as a mesh) and rotating it accordingly.

If you can figure this out please let me know! I have been trying to figure this out for an automated turret… I need to lock things to one axis, not rotate 360 degrees on every axis to look at player lol.

Get the Vector3.Angle difference and rotate it around the Y axis by that difference. You can use just the X and Z positions and zero out the Y for both the turret and looked at target.

Well, I thought about it like that, but I’m making an Online game, and I need it to recognize a tagged player.
I just can’t figure out how.

It’ a Turret, I need it to rotate around Y Axis and X axis… (Y to rotate the turrent) and X to rotate the barrel up and down just a bit.

But I just don’t know how to do it with a tagged object…

Such as, if a Tag of Red enters the trigger, try to aim at it and kill it.
I just want it to search for a tag that enters it, not a specific object.

For getting the tag on entering the trigger

function OnTriggerEnter (other : Collider) {
   
    if (other.transform.CompareTag("Red")) {
        AimTurret();
    }
}

Then to rotate the turret use the Y axis and Vector3.Angle. Then to rotate the gun up and down on the X axis do similar. You may want to use a Lerp function and a currentAngle and wantedAngle as the two parameters fed to the function and feed the result to the turret and gun.

That’s the part that confuses me.

First off, I’ve been curious - How do you do the Code stuff on fourms? I only ever see it on the Answers page to make the code in the box like you did. I’ve been wondering this lol.

But anyways, I understand how the tags part work, but as you put, it goes to another function called AimTurret();

How can I make something outside the trigger part know what to look at without being in the Trigger function?

Like for example void OnTriggerStay(Collider col);
if(col.gameObject.tag == "Red){
AimTurret();
}

void AimTurret(){

How do I make it know what to aim at in here, without being in the TriggerStay?

}

For the code stuff there is an insert button on the tools menu at the top. It looks like a text page just after the film clips and before the floppy disc.

On the AimTurret() use the transform from my version and pass it to the AimTurret(Transform target). Then use the target.position per frame to track it within the AimTurret function. Also… You only need to get this on OnTriggerEnter and then dismiss it at OnTriggerExit if I get what you want to do correctly.

As well… you may want to create a boolean named something like isCurrentlyTargetting. Then when that is true in Update you can call the AimTurret function. Probably make the currentTarget a class variable as well and then you don’t have to pass it to the AimTurret function as it will only track it when the boolean is true and the currntTarget is set in the OnTriggerEnter function.

Adding script to knife (parent)doesn’t work , when i add script there then ir will follow the player by making some distance from first position .

Yeh sure that’s rotation transform to work of knife in my game , https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB4QtwIwAA&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DTfRhQO5PcuQ&ei=_oCpVNz8IoadugSP2oLgCQ&usg=AFQjCNHN5H2syWOUqUrPVNuxKjbWWycz0Q&sig2=Y2pNPkw89s4E1Z_mfFs0Ag&bvm=bv.82001339,d.c2E

Here is tutorial about this , hope it helps you .

I scrolled through the timeline of the video and didn’t see a script editor open, so how’s that going to help LOL LOL LOL.

https://www.youtube.com/watch?v=TfRhQO5PcuQ

LOL

I added wrong video link ,

LOL

Here is that one.

https://www.youtube.com/watch?v=HiedjbXrHio

Script reference attached on description .

Guys please suggest me something it’s stopped here .

Keep trying. I have had to try 30-50 iterations and refactoring of code basics to get the special situation I wanted working at times. Get use to it. There is a meme in the Game Dev Memes thread where the guy looks at the computer with a puzzled look and the caption is something like “Hmm…code worked first time” like that is suspicious. It is. You will get used to throwing it at the wall till it sticks. That is why it is called development and not making.

Great said, thanks