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"

Finding nearest multiple of 90

I'm trying to attach together two actor, I want to get the nearest multiple of 90 degrees in the Z direction relative to the parent actor and then update the child actors rotation with the new number. My approach for this was to just find the nearest 90 degrees (which would be in the world) then add the parent objects rotation, which I thought would give me the result I was looking for. My problem is I can't seem to find the nearest 90 degrees consistently, is there a way to find this simply? This code id what I've been trying so far, it doesn't seem quite right. When I print the number it spits out it isn't even a multiple of 90. I figured this wouldn't be that hard to do? Thanks

alt text

Product Version: UE 4.16
Tags:
nearestmultiple.jpg (212.7 kB)
more ▼

asked Jun 26 '17 at 01:43 PM in Blueprint Scripting

avatar image

PatrickRegal
11 4 10 13

avatar image Irakli Jun 26 '17 at 01:56 PM

Can you please elaborate on a question a bit? In practical terms, what are you trying to achieve? "nearest multiple of 90 degrees in the Z direction relative to the parent actor" is a bit confusing

avatar image PatrickRegal Jun 26 '17 at 02:02 PM

Ya, the child actor can only be placed in four positions, each rotated 90 degrees differently on the Z axis, So i want to find this but it has to but relative to the parent, so if the parent has a Z rotation of 10 then the child needs to snap to 10, 100, 190, 280. I think I may have solved it

avatar image Irakli Jun 26 '17 at 04:17 PM

So basically you have 4 numbers (Parent rotation(PR), PR+90, PR+180, PR+270) and you wan to select the one thats closest to your child's rotation? Whats the logic of selecting them or do you always want PR+90? Can you please give this more sense by providing a gameplay example.

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

1 answer: sort voted first

I think I may have solved my problem, below is the new math i'm using. I then add this new number to the rotation of the parent object and it seems to be giving me the correct rotation.

alt text

nearestmultiple.jpg (136.6 kB)
more ▼

answered Jun 26 '17 at 02:07 PM

avatar image

PatrickRegal
11 4 10 13

avatar image PatrickRegal Jun 26 '17 at 02:10 PM

Actually never mind, seems to be off still.. hmm It looks good most of the time but when the closest degrees should be 180 or -180 it seems to think it should be 90 instead?

avatar image PatrickRegal Jun 26 '17 at 02:40 PM

When the original rotation was 118.489, it thought the nearest 90 degrees was -180.. Looking at some print statements I found that when walking through the math It should 118.489/90 = 1.316 which it should round to 1, but apparently it rounded to -2, weird

avatar image TextusGames Jul 01 '18 at 12:07 PM

Thank you.

(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