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 SweetRevenge · Dec 02, 2010 at 04:44 AM · walking

Basic mario style platform walking script

I want to make a basic walking script similar to a mario style game. I want the character to only be able to walk forward and backwards, and to be able to jump. I took a break from scripting so im kinda rough around the edges if anyone could help me out or reference a wiki that would be great. -Thanks

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kristov · Dec 02, 2010 at 05:12 AM

A tutorial for 2D gameplay is here: http://unity3d.com/support/resources/tutorials/2d-gameplay-tutorial . It's about everything to do with making a 2D game, but I don't think it walks you through the scripting process. Since it has an example project though, you can take a look at the scripts they use and how they work.

Good luck!

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

Answer by Rennat · Dec 02, 2010 at 07:36 AM

here's one approach that doesn't use physics or a character controller:

this script would go on your character (after you finish it)

public var runSpeed : float = 3; public var runSpeedDamping : float = 0.5; public var jumpSpeed : float = 4; // I made these values up, public var fallSpeed : float = 4; // they will need to be tweaked

private var isGrounded : boolean = false; private var velocity : Vector2 = Vector2.zero;

function Update () { // figure out if you're touching the ground // you could use a downward raycast or colliders/triggers isGrounded = ...

 // figure out how fast to move based on input
 velocity.x = Mathf.Lerp(velocity.x,
                 runSpeed * Input.GetAxis("Horizontal"),
                 runSpeedDamping);

 // jumping/falling
 if (isGrounded) {
     // if you're on the ground, stop the vertical movement
     velocity.y = 0;
     if (Input.GetButtonDown("Jump")) {
         // if you hit jump then give it some vertical speed
         velocity.y = jumpSpeed;
     }
 } else {
     // if you're not touching the ground, reduce your vertical
     // speed a little bit every frame.
     velocity.y -= fallSpeed * Time.deltaTime;
 }

 // apply the movement using only the X and Y axes
 var movementVector : Vector3 = new Vector3(
         velocity.x * Time.deltaTime,
         velocity.y * Time.deltaTime,
         0);
 // You should use some raycasts here to make sure you won't collide
 // with anything and if you do adjust your movement distance 
 // you can use movementVector.Normalize to get the direction of a ray
 // and movementVector.magnitude to get the length for the ray
 // if your raycast hits then `hit.distance * movementVector.Normalize`
 // will give you the new movement vector
 transform.Translate(movementVector);

}

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 Meltdown · Dec 02, 2010 at 11:23 AM

Also take a look at this link.. It contains 5 small 2-d game examples and goes through all the scripting.

Its in C# though...

http://forum.unity3d.com/threads/51017-5-Unity-game-examples-C-scripting-tutorial-for-beginners

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 saxenahimanshu266 · Jan 18, 2021 at 10:56 AM

https://www.codegrepper.com/code-examples/csharp/walking+script+unity

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

1 Person is following this question.

avatar image

Related Questions

C# Movement Script 0 Answers

How Come My Walking Script Doesn't Move the Character Forward? 1 Answer

Walking sound Script returns with Error: BCE0077 2 Answers

Hi, Could someone tell me why this is reversed? 1 Answer

Walking script not working need help 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