x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Have a turret rotate towards crosshair?

What's a good way to have a turret rotate towards a crosshair?

Product Version: Not Selected
Tags:
more ▼

asked Apr 26 '15 at 05:12 PM in Blueprint Scripting

avatar image

Taurian
291 34 52 69

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Here's the solution.

alt text

capture.png (127.9 kB)
more ▼

answered Apr 27 '15 at 08:44 PM

avatar image

Taurian
291 34 52 69

(comments are locked)
10|2000 characters needed characters left

You should use "Make Rot From X" node. The input vector for this node should be (crosshair_location - turret_location). The output will be Rotator which you can youse for SetActorRotation node. You may also use just yaw component if you meet some issues or need only z-axis rotation (just use MakeRotation node and get yaw from your obtained rotator and other components form your turret's original rotation)

It may look like this: alt text

Hope that helps.

111.png (103.3 kB)
more ▼

answered Apr 26 '15 at 05:26 PM

avatar image

KeltRivera
113 4 7 111

avatar image Taurian Apr 27 '15 at 03:43 AM

The turret is actually a component on the pawn that I'm controlling. I've copied the nodes as much as I can but the turret appears to have a mind of it's own: alt text

capture.png (172.1 kB)
avatar image KeltRivera Apr 27 '15 at 01:55 PM

Everything should work like a charm. You should check: 1) Your turrent component alignment (x axis should be along the trunk, z - upwards) 2) Correctness of your function for converting mouse input to aim coordinates (may be try to draw the debug sphere to check it).

I was up to perfofrming simple test for you and here's results:

1)test turret blueprint (note the axis alignment) alt text

2)turrent blueprint tick function alt text

3) the result alt text

And the same for "locked axis" rotation I mentioned before: (not that turrent is rotated towards the aim, but it does not look upwards to it in this case) alt text alt text

turret_bp.jpg (277.5 kB)
turret_aim_bp1.jpg (130.4 kB)
turret_aim1.jpg (159.4 kB)
turret_aim_bp2.jpg (200.9 kB)
turret_aim2.jpg (155.5 kB)
avatar image Taurian Apr 27 '15 at 03:40 PM

It's pointing to the mouse "literally". So it's always pointing "backwards" towards the mouse. (Since the camera is behind the turret).

Is there a quick way to reverse this? Or should I try pointing it towards a cross hair material in front of the actor?

alt text

capture.png (135.3 kB)
avatar image KeltRivera Apr 27 '15 at 04:06 PM

You should basically cast the ray from your camera and get the location of this hit. However for the mouse it looks like there is simlier solution. Just look at the accepted answer here: https://answers.unrealengine.com/questions/148930/have-a-static-mesh-follow-the-mouse.html

Good luck with your project.

avatar image Taurian Apr 27 '15 at 05:17 PM

It didn't work. I think the solution is some how related to the "World Direction."

I'll keep trying.

avatar image KeltRivera Apr 27 '15 at 08:13 PM

Now looking at cursor crosshair (pretty good): alt text

and corresponding blueprint: alt text

avatar image KeltRivera Apr 27 '15 at 08:17 PM

May be you can post some screenshot\more info on your setting? Still not sure if your turret's first person, third person or top-down

avatar image Taurian Apr 27 '15 at 08:21 PM

It's third person. I was able to get it to work with this though:

alt text

capture.png (127.9 kB)
avatar image KeltRivera Apr 27 '15 at 08:42 PM

finally got it :) piece a cake at the end! You don't need all these exessive nodes.

1)aim alt text 2)bp alt text

Please consider to be more specific from the start next time :) Good luck!

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question