Source SDK

Source SDK

Pacca Oct 9, 2016 @ 12:34pm
How to make an object rotate to face the player (Portal 2)
How would I make a point entity always attempt to point in the direction of the player? Despite some intense google searching, I found nothing on how to do this in Hammer. The best I got was how to make an object rotate forever at a given speed, which obviously isn't what I need. What should I parent the entity to to make it rotate like this?
Originally posted by Mandrew:
Hey Pacca, here is a way to do it in steps:
Looking at player on sight (setting up)
1. Make a brush entity of the texture of your choice.
2. Make the brush entity to a func_tank (name this entity)
2. Make an npc_enemyfinder (name this entity)
3. Make an ai_relationship (optional to name)

Setting Up The Entities

1. ai_relationship
1. "subject(s)" = Name of your npc_enemyfinder
2. "Target(s)" = player
3. "Disposition" = Fear
4. "Start Active" = Yes
2. npc_enemyfinder
Keys:
1. "FieldOfView" = -1 (optional if you want the object to see you in every direction)
Outputs:
Output Target Input
OnFoundEnemy The name of your func_tank SetTargetEntity
OnLostEnemy The name of your func_tank ClearTargetEntity
OnLostEnemyLOS The name of your func_tank ClearTargetEntity

3. func_tank
1. Rate of Fire = 0
2. "Yaw rate" = "Speed of Left/Right rotation"
3. "Pitch rate" = "Speed of Up/Down rotation"
4. "Yaw range" = "How far this entity should rotate from left to right" (180 means it can rotate all around)
5. "Pitch range" = "How far this entity should rotate from up to down" (180 means it can rotate all around)
Flags
Active (Checked)
Non-Solid (Optional)
4. Parent the entities you want to func_tank and you should have rotating objects.

EDIT: If you want your entity to always face the player no matter if it is visible or not, let me know. You can always friend me for hammer editor help, I also just noticed you were the creator of the map "Weaponry in Portal 2", good map by the way :).
< >
Showing 1-8 of 8 comments
holly’s tea Oct 9, 2016 @ 1:40pm 
I believe
func_tracktrain has a option to face the player - but do you need an entity that looks
a) same direction like the player
b) towards the player
Rectus Oct 9, 2016 @ 1:43pm 
There might be an entity for it, but I can't remember. The only way I know for certain is with a script. Here is one I made for L4D2, but it should work for Portal 2 as well.
https://developer.valvesoftware.com/wiki/L4D2_Vscript_Examples#Making_an_entity_orient_itself_toward_a_player
Pacca Oct 9, 2016 @ 2:14pm 
I need the entity to face towards the player, preferably with some lag in it's movement. Looking at the wiki page for func_tracktrain, as well as it's info in hammer, doesn't seem to reveal a feature like what I need.

I also don't have any experience with scripts or how to package them with maps, so I'd prefer an entity oriented approach (I appreciate the answer, though, and will probably use it if push comes to shove).
Pacca Oct 9, 2016 @ 3:06pm 
I tried implementing the script, and I can't get it to work. I removed the if statement for checking for survivors because that obviously won't work in portal 2. However, the script still seems to have no effect. I applied it to the entity at hand, and then tried to apply it to a func_tracktrain and parented the entity I want to move to it. It still sits as if nothing has changed. I know the object can be parented properly, so that isn't an issue.
Moltard Oct 9, 2016 @ 9:36pm 
Func door rotating can rotate to a specific angle.
Pacca Oct 10, 2016 @ 12:54am 
Can I specify that angle based on the players position?
Snoopy Oct 10, 2016 @ 3:12am 
Originally posted by Pacguy64:
Can I specify that angle based on the players position?

Not sure but maybe point_anglesensor would work
The author of this thread has indicated that this post answers the original topic.
Mandrew Mar 28, 2019 @ 7:34pm 
Hey Pacca, here is a way to do it in steps:
Looking at player on sight (setting up)
1. Make a brush entity of the texture of your choice.
2. Make the brush entity to a func_tank (name this entity)
2. Make an npc_enemyfinder (name this entity)
3. Make an ai_relationship (optional to name)

Setting Up The Entities

1. ai_relationship
1. "subject(s)" = Name of your npc_enemyfinder
2. "Target(s)" = player
3. "Disposition" = Fear
4. "Start Active" = Yes
2. npc_enemyfinder
Keys:
1. "FieldOfView" = -1 (optional if you want the object to see you in every direction)
Outputs:
Output Target Input
OnFoundEnemy The name of your func_tank SetTargetEntity
OnLostEnemy The name of your func_tank ClearTargetEntity
OnLostEnemyLOS The name of your func_tank ClearTargetEntity

3. func_tank
1. Rate of Fire = 0
2. "Yaw rate" = "Speed of Left/Right rotation"
3. "Pitch rate" = "Speed of Up/Down rotation"
4. "Yaw range" = "How far this entity should rotate from left to right" (180 means it can rotate all around)
5. "Pitch range" = "How far this entity should rotate from up to down" (180 means it can rotate all around)
Flags
Active (Checked)
Non-Solid (Optional)
4. Parent the entities you want to func_tank and you should have rotating objects.

EDIT: If you want your entity to always face the player no matter if it is visible or not, let me know. You can always friend me for hammer editor help, I also just noticed you were the creator of the map "Weaponry in Portal 2", good map by the way :).
Last edited by Mandrew; Mar 28, 2019 @ 7:36pm
< >
Showing 1-8 of 8 comments
Per page: 1530 50

Date Posted: Oct 9, 2016 @ 12:34pm
Posts: 8