Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
7
Question by SrBilyon · Oct 12, 2010 at 07:39 AM · rotation2d-platformerpathsplineside-scrolling

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?)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by Loius · Oct 13, 2010 at 02:29 AM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3
Best Answer

Answer by pixelplacement · Oct 17, 2010 at 05:08 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1
Best Answer

Answer by Mattivc · Oct 13, 2010 at 08:14 AM

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SrBilyon · Oct 13, 2010 at 08:25 AM 0
Share

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!

avatar image pixelplacement · Oct 14, 2010 at 01:50 AM 0
Share

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

avatar image SrBilyon · Oct 14, 2010 at 06:26 AM 0
Share

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.. :(

avatar image
2

Answer by Adam Rademacher · Oct 13, 2010 at 02:12 AM

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SrBilyon · Oct 13, 2010 at 02:29 AM 0
Share

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...

avatar image Adam Rademacher · Oct 13, 2010 at 02:54 PM 0
Share

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.

avatar image Adam Rademacher · Oct 13, 2010 at 02:55 PM 0
Share

(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

avatar image SrBilyon · Oct 14, 2010 at 06:01 PM 0
Share

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

avatar image
0

Answer by scone · Jan 07, 2013 at 03:25 AM

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

iTween and 2D Platforming Tutorial Merge: Rotation of player and camera needed 1 Answer

PutOnPath iTween spline but not restrict in the up direction (jump) 3 Answers

How to go about constraining a player to a path? 0 Answers

Local scale flip is breaking rotation 1 Answer

Tank (Rigidbody) Pathfinding movement 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges