x


Restrict a player's movement to a path for a 2.5D game that has curved paths

There are some MMO games called "Fists of Fu" and "Elsword" that I was analyzing as I was trying to find recent examples of a 2.5d side scroller. There are points when the path "wraps around" a structure such as a mountain and although the path isn't straight, the character (and camera) rotates while making sure that the player still walks forward on that given. I'm assuming that only the player's X is being used for movement, but I don't know how I would make the character follow a path AND rotate accordingly.

alt text alt text

This PvP recording shows the rotation I was going for: http://www.youtube.com/watch?v=LiK6UPtYCBw&feature=related and http://www.youtube.com/watch?v=yhrZRbT-wEk&feature=related

So how are they accomplishing this? I assume that the player and camera are being rotated on the Y axis, but how does the system determine when, (or how) to rotate the player and make sure that the camera is always facing the player's side?

BTW: I'm Using the 2D Platforming Tutorial as a base..

Edit: I Imported the spline controller for the Unitycommunity wiki: http://www.unifycommunity.com/wiki/index.php?title=Spline_Controller and I can have an object move around the path, but that's all it does. It doesn't rotate the object to make it face a constant direction (forward vector logic needed possibly?)

more ▼

asked Oct 12 '10 at 07:39 AM

SirVictory gravatar image

SirVictory
1.7k 66 77 104

(comments are locked)
10|3000 characters needed characters left

6 answers: sort voted first

I think the most effective and general purpose solution would be to use a Bezier Curve / 'Spline' interpolation technique -

Anything that interacts with the player would have something along the lines of:

var x : float;
var y : float;
private var spline : SplinePath;

function CalculatePosition() : Vector3 {
  return spline.WorldPosition( x ) + Vector3(0,y,0);
}

A SplinePath would consist of a series of points, and when you ask it for a position it will choose a point along a smooth path based on those points.

The idea is that .WorldPosition(x) will calculate the ground level at a certain "X" position in the level, then you'll add on any vertical changes your character has (jumping, etc).

Obviously the tough part of this is the SplinePath.WorldPosition function, but there are quite a few examples of this on the web. If I remember correctly there's a very nice Spline script available on the unity3d forums in the scripting section. If it's not exactly what you need, it'll be pretty close. Try searching for Spline or Bezier curve paths.

more ▼

answered Oct 13 '10 at 02:29 AM

Loius gravatar image

Loius
10.7k 1 11 41

(comments are locked)
10|3000 characters needed characters left

Just put an example together on the support site for iTween that I hope helps out with this. If you parent the camera to the character in this example and offset it from its right shoulder you will be able to have a camera that follows around curves. Hope it helps: http://itween.pixelplacement.com/examples.php

more ▼

answered Oct 17 '10 at 05:08 AM

pixelplacement gravatar image

pixelplacement
682 8

(comments are locked)
10|3000 characters needed characters left

You should also take a look at iTween it has a few path interpolation options that migth help you out.

more ▼

answered Oct 13 '10 at 08:14 AM

Mattivc gravatar image

Mattivc
1.7k 55 60 67

I've purchased an iTween package a couple of hours ago (only 2 buck) and I have half of what I need done! I just need to figure out the camera rotation part and I'm good!

Oct 13 '10 at 08:25 AM SirVictory

Glad iTween was able to help out! Would love to see what you come up with!

Oct 14 '10 at 01:50 AM pixelplacement

I was going to post the project to see if anyone would be able to figure out why the rotation would work, but it includes some the the iTween PutOnPath code.. :(

Oct 14 '10 at 06:26 AM SirVictory
(comments are locked)
10|3000 characters needed characters left

You might have a trigger that tells your camera and player that they are on a corner. Then maybe a distance check and/or dot product once they enter the trigger to determine the orientation of the camera and player...A trigger based system is probably the easiest to implement.

more ▼

answered Oct 13 '10 at 02:12 AM

Adam Rademacher gravatar image

Adam Rademacher
1.1k 1 3 19

I was thinking this, but I didn't know how to interpolate the orientation in code. I am trying to use iTween, but when I combine it with the 2d-platformer example, it's not working correctly...

Oct 13 '10 at 02:29 AM SirVictory

Try using a Quaternion Slerp on the camera. It takes a from rotation, a to rotation, and a ratio (t). You set the from rotation to the original camera position, the to rotation to the sideways view, then base the ratio off of the distance travelled across the corner divided by total distance.

Oct 13 '10 at 02:54 PM Adam Rademacher

(Sorry for double comment) The other thing you could try is a Transform.RotateAround and set the angle of rotation based off of distance. You'd have a pivot point in the center of the corner, then rotate the camera

Oct 13 '10 at 02:55 PM Adam Rademacher

Thanks, I ended up using iTween to help me, but I still am having problems with it...

Oct 14 '10 at 06:01 PM SirVictory
(comments are locked)
10|3000 characters needed characters left

Hey there!

I'm the guy who created the spline system :)

I believe that it should do exactly what you're looking for. Oddly enough the code that I'm looking at doesn't have a flag that I remember adding for whether to affect the object's rotation. The default behavior should be to Lerp the object's rotation so that it's Z is looking down the spline in the direction that it's moving.

Lines 197-204 in SplineController should do that. If they aren't maybe your rotation damping value is at 0 for some reason? Let me know if you still can't get this to work!

more ▼

answered Jan 07 at 03:25 AM

scone gravatar image

scone
17 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2173
x240
x78
x53
x43

asked: Oct 12 '10 at 07:39 AM

Seen: 3657 times

Last Updated: Jan 31 at 05:32 AM