I am trying to launch my character toward my cursor location in a topdown game

I have spent the last 3 days trying to figure out this problem. I will admit that I am new to Unreal but have not found any tutorials on this particular topic.

My goal: I want to launch my character toward my cursor location. If the location is within range, they will land at the impact location. If they are out of the range, they will be launch toward the impact location. As of right now, I am simply trying to figure out how to launch my character in the direction my mouse is oriented from my character.

What I have been able to achieve: I have been able to launch my character a set distance in the direction the character is facing successfully.

Here is what I have for my blueprint currently:

I am certain I am doing something absolutely wrong but have no idea what. I hope you all can help me figure it out.

I failed to mention in the post that this is the default project for a topdown game and I created this blueprint in the TopDownCharacter blueprint.

I just tried this:

That error is saying: Hit must have an input wired into it (by ref params expect a valid input to operate on).

I think what that means is that my CastLocation function is not a valid place to trace from. The goal of my CastLocation function was to return the value of my current cursor location from my TopDownController.

Then I would be able to draw a line from the location of my character to the location of my cursor, get the direction I want to launch toward with GetWorldRotation and then launch in that direction.

Ok, at first I could see you are trying to collect the hit info but your call of LineTraceByChannel seems never been called.

I have a few things to say about it. First, your Cast Location function will only return a value, without any execution node needed, so you may mark it as pure Second, after you set Can Dash, link the execution node(the white line) to the LineTraceByChannel, and the exec of it, you will link to Launch Character.

Okay, so I linked up the nodes correctly now based on your comments. Here is what I got:

Could you explain what you mean by ‘pure Second’?

So now when I execute the skill, my character is being launched north and not in the direction of the cursor. Is my get world rotation and forward vector not returning the direction of my mouse to my character?

It seems the forum editor didn’t got my line break. I’ll use double line now…

it’s just mark it as pure.

Take a look on the picture you have sent. You see how the GetWorldLocation doesn’t recieve an execute line but the LineTraceByChannel does?
The pure functions are just this, you don’t need to pass the execute line on it, it’ll just give the value you want.

Now, back to your problem. The Cast Location is not a pure function, so if you don’t pass the execution line to it, it won’t get any value at all. so, open that function, click on the node with the funcion name (the first one where you pull out the white line) and check the box “pure” that should be on the properties at left, right above the place where you define what vars it get in and out.

If it solves your problem, please, come back here and mark it as resolved, so that could help the others with the same problem as you.

Oh, that makes a lot more sense! Thank you!

Now the cast location function requires a target though.

In which blueprint is the function Cast Location?

It is located in my topdown controller blueprint. My Q_Ability is written in the TopDownCharacter blueprint.

I created the CastLocation function in the TopDownCharacter blueprint and the error disappears. I named the new function MouseTarget. No errors when I compiled but I had the same result as before. I would get launched north from my character location. Also I had a runtime error that popped up after I closed.

You need to test the Return Value of LineTraceByChannel, it might have no collision at all…

Sorry, I’m not sure what you mean. How would I test that?

The LineTraceByChannel function has two outputs, one with the hit result, and another to check if it hit something or not. Just link that Return Value to a branch. if true, link it the Launch Character, if false, link it to something else

Alright, so I set it up like so:

The print string is returning FALSE when I try to launch to an area with no NavMesh on it. However when I click on an area with Navmesh, I am still being launched north and not in the direction of the cursor. It seems like the issue is that I am not getting the actual direction of my cursor from my characters position.

on that Hit Component, there is another data, I’m thinking that you may use just the “normal” on that multiply node instead of the forward vector. If that doesn’t work, try to find the lookat rotation between your character’s location and the “location” on Out Hit

Using Normal Results:
When using the normal to launch, im seeing some weird functionality. If I click on the floor, he gets launched straight into the air. If I click on one of the pillars in the default level in the topdown blueprint, I get launched in the opposite direction of where my cursor is.

Using Lookat Rotation Results:
YES! So I took my get world location and mouse target location function and plugged it into the Find Look at Rotation then plugged those into Get Forward Vector like you suggested. This launches my character in the correct direction now. However I am noticing when I select a point of elevation, my character will bounce off of it depending on the trajectory. Im sure I can set something up to stop my character when coliding with something but the basic functionality is exactly what I was looking for! Here is my blueprint:

Thank you very much for your help, lotti!

1 Like

Ohh, good call! thanks, lol.

Glad to help!
and btw, you are setting “Can Dash” false twice.