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"

How to make a character orbit a target with AddMovementInput

I'm trying to make a character orbit its target in a 3rd-person 3d game, similar to the way zelda or dark souls does it. With what I have now the character spirals out the longer you press the strafe button. I'm trying to take the velocity vector that the movement component creates and angle it so it falls on the orbit path. The formula I'm using for the rotation angle (the one under the character) is:

Angle = ArcCos(.5*V/R)

where V is the speed and R is the circle's radius (distance to target).

alt text

This is the blueprint I have. The output vector goes straight into the add movement input node with a scale of ABS(axis input).

alt text

What am I doing wrong here? Is there a simpler way to do the same thing?

Product Version: Not Selected
Tags:
strafe vector.png (167.9 kB)
diagram.png (8.3 kB)
more ▼

asked May 16 '15 at 12:03 PM in Blueprint Scripting

avatar image

vellyr
6 2 3 5

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

1 answer: sort voted first

What is your camera doing during all this? If your character's rotation is always following the camera, and the camera is always facing directly at the target, then your strafe should be constantly adjusting to a 90 degree angle at all times, creating a perfect circle on its own.

more ▼

answered May 16 '15 at 03:56 PM

avatar image

PixelOmen
617 21 16 35

avatar image vellyr May 17 '15 at 02:02 AM

My character is constantly rotating to face the target, which is a function I call from tick. The camera is rinterped to follow with a slight lag. I originally tried what you described, because it sounds like it should work, but it makes the spiralling even worse.

Here's the camera/actor rotate function (get control rotation should be connected to the rinterp node): alt text

tracktarget.png (248.3 kB)
avatar image PixelOmen May 17 '15 at 08:14 AM

Ok, yeah i tried it out and I see what you mean. It doesn't really make sense. Regardless, I've come up with a way to compensate for it. It's a bit brute force, but it seems to work fairly well in my test.

I made a custom event that gets the vector length between the target and the player and puts it in float variable, let's call it "TargetDistance".

I trigger this event (to update the target distance) when I initially lock on and every time the absolute of the InputForwardAxis is greater than .1.

Then, at the end of the rotate function (every tick) I check to see if the current vector length is equal to the "TargetDistance".

If not, I set the current location of the character forward/backwards by adding/subtracting any increment to the forward vector. It will do this every tick until it matches the "TargetDistance" again.

Using this method I was able to keep the player on a perfect radius around the target at all times without any significant side effects. You might have to finesse some of the minor details but the concept seems to work. Let me know if you want pictures.

avatar image vellyr May 17 '15 at 12:57 PM

Thanks, the orbiting works now, but it won't let me move forward or backward. I'm probably doing something dumb though, I'll check it again tomorrow.

(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