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
0
Question by Hyllain · Jul 06, 2013 at 09:37 PM · collision2d-platformerjumpinggrounddepth of field

2D game with depth, basics?

Hello!

I'm currently working on a 2D game with depth, something similar to Castle Crashers.

I'm trying to do the basics first(character moviment, collisions, etc), what I have so far is this:

alt text

My background is a Plane object (with a background image) facing positive Z. Both the character and the chest make use of a 1x1 Quad (custom mesh) with their respective image. For collisions, i added a capsule collider to my character and a cube mesh colider to the chest object. My character also has a Kinematic rigid body attached to it.

I managed to create a script for moviment and collision that works as follows:

  • Moving to the Right of Left = increasing/decreasing transform.X value

  • Moving Up and Down = increasing/decreasing transform.Y and Z values

  • Collision = OnTriggerEnter

So far i had no problems, but now i'm having trouble on the jump part. As you can see i have no ground on my scene(maybe I should have?), that's why my character's rigid body is Kinematic. I have tried to increase the rigidbody velocity and decrease it over time, (until my character returned to the initial Y position) but it doesn't really work...

My questions are:

  1. Should i add ground on my scene for colision? so i could use a non-kinematic rigidbody. If yes, how can i achieve this?

  2. If Kinematic rigidbody is the right choice, how can i script the jump?

  3. Does the Character Controller provided by Unity has a jump funcionality? Still, it's restricted to a capsule collider :(

I hope that anyone can help.

Thanks!

unityss.jpg (218.8 kB)
Comment
Add comment · Show 4
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 Em3rgency · Jul 06, 2013 at 09:40 PM 0
Share

You could add another plane, "the ground", perpendicular to your background one. You can disable the mesh renderer to make it invisible. Have it move up and down along with the character, but NOT when he tries to jump.

This way you can solve your problem by finding one of the many 3d jumping script tutorials.

avatar image Fattie · Jul 06, 2013 at 10:39 PM 0
Share

BTW, it's incredibly easier to use 2DToolkit for something like this

avatar image Em3rgency · Jul 06, 2013 at 10:46 PM 0
Share

Yeah, it probably is. I just don't do 2D, so my brain automatically goes "How can I turn this into a 3d problem?" :D

avatar image Hyllain · Jul 07, 2013 at 06:37 PM 0
Share

Great idea Em3rgency, i will try this out :) What would be best to use in my case: $$anonymous$$inematic or non-kinematic rigidbody? With a non-kinematic rigibody i had some collision issues, my character keeps bouncing when touching another collider (i.e. the wooden chest).

@Fattie This toolkit looks good, but i don't wanna pay for it(i like program$$anonymous$$g) ;)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by trs9556 · Jul 07, 2013 at 08:30 PM

Instead of increasing/decreasing the velocity over time why don't you make it more static.

Set the height of the jump. Maybe like "5" units, whatever suits your needs.

From there when you hit your jump button you use lerp to move your character 5 units up, once it has reached it's 5 units, lerp it back down 5.

Using

     character.transform.position = Vector3.Lerp(character.transform.position, desiredLocation.position, Time.deltaTime * speed);

When you start your jump declare desiredLocation as your current location plus 5.

Check if you have reached your destination

     public float ErrorAllowed = 0.005f; //the smaller the number the more accurate
     if (Mathf.Abs((character.transform.position.y - desiredLocation.position.y)) < ErrorAllowed) {
         //method that goes down. Aka a bool to let you know if you are traveling up or down, and then to change the desiredLocation back to either your start location (more accurate) or current location minus 5
     }


Now one thing I like and hate depending on what I'm doing is with lerp it gradually slows down. So you can compensate for this by increasing your speed. I do something along the lines of:

     public float FloatForSpeedUp = 1.7f; //play around with this number.
     if ((Mathf.Abs((theCamera.transform.position.y - tempPositionToGoTo.position.y)) < FloatForSpeedUp)) {
         speed+= (speed*0.04018f);
     }


The biggest downside to this is your FPS determins a lot of the simulated physics on this. I noticed the speed at which my object excels in the editor (on my pc) is much more dramatic then on my android phone (I use these for android) basically because my computer gets 800+ FPS while my android gets 40-60. So fine tuning around will be required.

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
0

Answer by bscarl88 · Jul 15, 2015 at 05:44 AM

What if... You have an object that is your "Shadow" that is platform controlled in an 8 directional way, this is what you control, so it moves freely around the screen in the X and Y axis. Then you have a Platformer style Player object with Graity in the Y axis. This Player object essentially uses his "Shadow" like a hoverboard. When the shadow is moving, his walk animation goes off as he is pinned to the shadow's movement. Then the player can initiate a jump and they're just landing back down on a the shadow platform. Or is this just better to do with a script and an offset?

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

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

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me with the jumping in this Player Controller script? 1 Answer

Jump if ground is detected 1 Answer

Delay Jumping 3 Answers

Box collider didn't jump with player 1 Answer

2D NPC should kill player on collision but does not. 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