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"

Getting location of middle of my grid?

I made a grid (well, it's just a plane with texture tiled 250x250 so I have 250x250 squares).

It works just as I need but I am having trouble snapping to middle of square. Each square is 100x100 size.

alt text

I have a function called getCursorPosition (which as name suggests - gets cursor position in game space). alt text

This function also calls another function - getNearestSnap (which should ideally get nearest square center). (My grid points are just based on coordinates in world space, it doesn't check for grid lines or anything as it's just texture).

alt text

The issue is in getNearestSnap. If I change values to 100 - it works okay (but it ends up on grid lines rather than in middle of each square). Since I changed it to 50 - it snaps to both - grid lines, grid intersections and square centers.

I need to limit it to snap to square centers only (so get nearest square center pos).

Product Version: UE 4.22
Tags:
full.png (185.8 kB)
snappos.png (102.4 kB)
grid.png (1.2 MB)
more ▼

asked Apr 14 '19 at 06:56 PM in Blueprint Scripting

avatar image

arleitiss
12 1 1 6

avatar image Everynone Apr 14 '19 at 09:40 PM

So add 50? No? Also, there are some snapping nodes that may work for you.

avatar image arleitiss Apr 14 '19 at 11:31 PM

150 didnt work

avatar image Everynone Apr 15 '19 at 05:24 AM

Are you multiplying by 150 or adding 50 to the end result?

avatar image arleitiss Apr 15 '19 at 07:28 AM

Adding 50 to X and Y end result.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Set it to 100 to get the grid lines and then add 50. If you set it to 50 and add 50 you'll just hit the lines again.

alt text

Image from Gyazo

capture.png (179.9 kB)
more ▼

answered Apr 15 '19 at 09:06 AM

avatar image

Everynone
15.2k 77 25 62

avatar image arleitiss Apr 18 '19 at 05:00 PM

Hi, it worked in a way. There is slight mis-functionality, would you perhaps know approach I could take to solve it?

See in this video I made: https://youtu.be/WxS29l6mVKc

It appears to snap to nearest grid only when it's +50 into next one, would it be possible to somehow snap into that square as soon as mouse enters it?

avatar image Everynone Apr 18 '19 at 05:43 PM

I'd just make the grid divisible by 2 (so 24x24) instead, so you never need to worry about offsets since you'll be applying them to everything further down the line. One less thing to worry about:

alt text

Image from Gyazo

edit: or just move the grid...

capture.png (247.9 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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