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 a Spawn Transform in the direction the player faces and the camera inclination

Hello !

As the title says, I am trying to spawn an actor (with SpawnActor node) giving him a Spawn Transform so that the actor goes in the proper direction. The context is quite simple : it is a fireball (projectile) the player sends away.

I would like to get a Spawn Transform in the same direction XY the player faces and to modify this vector so that the projectile goes upwards/downwards the same way the camera is inclined.

I achieved the first part (spawning projectile from the player in the direction he faces) without too much trouble. However I cannot figure out a way to just add a modification on the Z axis from the camera inclination without messing up the X and Y axis.

The blueprint I've got right now : alt text

  • I think I might not use the proper method to get inclination of the camera (ConvertMouseLocationToWorldSpace seems odd to do that but that's what I figured out).

  • Transform Rotation is (I guess) where everything messes up. Even though I put 0 in the scale for X and Y axis in Make Transform, the Transform Rotation still messes up the X and Y axis.

Does what I'm doing make any sense at all ?

Surely there is a much simpler way to just modify Z axis that I missed ?

The blueprint as showed above in video if you want to see it in action : https://www.youtube.com/watch?v=nLcJ8kYT-AQ

EDIT : to simplify the problem we assume we just want it to spawn from the player, not the hand of the player (I guess that translation in space shouldn't be an issue)

Product Version: UE 4.21
Tags:
more ▼

asked Mar 30 '19 at 09:35 PM in Blueprint Scripting

avatar image

N0rgannon
36 1 2 4

avatar image ThompsonN13 Mar 30 '19 at 09:50 PM

have you tried just using the control rotation of the player camera for the rotation? it seems like you just trying to shoot a projectile from a place in front of the character toward the direction the camera is facing.

alt text

capture.png (133.9 kB)
avatar image N0rgannon Mar 30 '19 at 09:58 PM

I just tried your version. It is so much simpler and understable and works wonders !! Thank you very much ! It is exactly what I was looking for :D

avatar image N0rgannon Mar 30 '19 at 09:59 PM

Oh no there is a small problem it sends the projectile in the direction the camera faces, not the player I didn't notice at first

avatar image N0rgannon Mar 30 '19 at 10:34 PM

I slightly modified your version to make it send projectile in the direction the player faces. I don't know if I should modify the Right and Up vectors as well ? It works fine except that the angle upward/downward seems to be stuck between +45° and -45° and I can't figure out why. But that's a much minor problem.

Blueprint modified for anyone wondering : alt text

avatar image ThompsonN13 Mar 30 '19 at 10:44 PM

wouldnt it be easier to use a make rotator then split the rot pin and just take the values you need instead of doing all the math? for example you could take the x and Z from the character which would control the roll and yaw of the projectile, then you could take the y from the camera to control the pitch.

avatar image N0rgannon Mar 30 '19 at 11:22 PM

I'm not sure to understand how to do what you are saying. Roll, yaw and pitch are a bit too abstract for me. I'll try to look it up tomorrow. On another note, I did understand why it doesn't go above 45°. I should normalize my vectors so that when inclination is high, translation on x and y decreases. I guess that is the math you say I could try to avoid.

avatar image ThompsonN13 Mar 30 '19 at 11:50 PM

you may actually need some math if you intend to from the characters hand via a socket.

but anyways the below picture shows what i meant. as for the roll pitch and yaw those terms come from flying planes and they are simpler than you may think. for roll imagine you do a cartwheel, your rolling your body to the side (for ue4 rotation on the X axis). pitch would be a somersault, your rotating your body in a forward or back direction(ue4 rotation on the Y axis). yaw would be like turning in place whilst standing (ue4 Rotation on the Z axis).

alt text

capture.png (181.4 kB)
avatar image N0rgannon Mar 31 '19 at 10:23 AM

That is 100% what I was trying to achieve ! Thanks a lot ! If anyone new like me reads this and has trouble reproducing the BP, to get the Roll Pitch and Yaw in the GetActorRotation instead of a rotator, you have to right click on the rotator and choose "Split struct pin". I couldn't figure out how to reproduce the blueprint at first because of this.

I didn't need to do math to spawn projectile from hand I simply added a socket on the middle finger and used that location (mid animation).

So the final version looks like this : alt text

For anyone curious of seeing it in action here's a video : https://www.youtube.com/watch?v=MOjTewm7vT0

The only issue I see may be that the hand being off-centre it might be slightly odd to aim that way. I think I'll just put the character off-centre so that the hand ends up in the middle where the cross aim would be when at mid cast animation. But that's a whole other topic. The projectile is 100% good :> Thanks again for your help :D

EDIT : forgot to clean up BP before taking the screenshot

avatar image ThompsonN13 Mar 31 '19 at 10:49 PM

also instead of the split struct pin you could have also dragged off the rotator pin and searched for break. that will give you a break rotator node. personally though i prefer the split struct pin as its a bit cleaner in this case.

avatar image N0rgannon Apr 01 '19 at 06:33 PM

Ok, didn't know that, dully noted ! Thanks again :D

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

0 answers: sort voted first
Be the first one to answer this question
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