gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Hello, can you help me with blueprint code in unreal engine, how make attack event by…
- User
Hello, can you help me with blueprint code in unreal engine, how make attack event by clicking left mouse button and rotate player character to cursosr position?
- Assistant
Certainly! Here's an example of how you can achieve this in Blueprint code in Unreal Engine:
- Create a new Blueprint class for your player character.
- Open the Blueprint Editor for your character and create a new function called "Attack".
- Inside the "Attack" function, add a "Line Trace by Channel" node. This node will be used to detect the location of the cursor.
- Connect the "Start" input of the "Line Trace by Channel" node to the "Get Actor Location" node for your character.
- Connect the "End" input of the "Line Trace by Channel" node to the "Get Hit Result Under Cursor by Channel" node.
- From the output of the "Line Trace by Channel" node, pull off a "Get Hit Location" node.
- Connect the output of the "Get Hit Location" node to a "Find Look at Rotation" node.
- Connect the "Rotation" output of the "Find Look at Rotation" node to the "Set Control Rotation" node. This will rotate the player character to face the cursor.
- In your player character's Blueprint Event Graph, add an event for the left mouse button click. Connect this event to the "Attack" function you created earlier.