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 MSB · Aug 06, 2013 at 12:21 PM · buttoncontrolrunningrunner

There has to be a more efficient way than this! (Simple running man game)

Heya everyone, super long question..try this one!

I'm working on a simple infinite running game (think Temple Run) and I've been working on the controls for the player for a day or so now.

The basic control system I want to work like this...

It's controlled with just the up and down arrow, Up for Jump, Down for Duck.


Press and hold Up = The player jumps and hangs in the air until.... Release Up = The player returns to running.

Press and hold Down = The player Ducks and stays ducking until ....Release Down = The player returns to running.


Simple enough until you need to switch between Jumping and ducking quickly leading to moments where you are for a moment holding both up and down so what I want to happen is...


Press and hold Up

(You jump over the danger but oh no! you need to duck now!) With Up still being held, the player then anticipates this by also holding down)

Now both Up and Down are held for a split second

(The player is still jumping at this point from the up button being held first from before)

Release Up (From letting go of Up, the player snaps to ducking)

Only Down Is now being held


And vice versa needs to happen, Holding Down to duck, preloading Jump by holding Up, releasing Down and snapping to a Jump.

Here's my code at the moment...

 var Run : GameObject;
 var Jump : GameObject;
 var Duck : GameObject;
 
 var Jumping : boolean = false;
 var Ducking : boolean = false;
 var PreloadRunning : boolean = false;
 
 var StopRunning;
 var StopJumping;
 var StopDucking;
 
 function Start(){
 
 RunStart();
 }
 
 
 
 
 function Update(){
 
      if(Jumping == true){
      if(Input.GetButtonDown("up")){
      print ("up arrow key is held down");
      
     
      Ducking = false;
      RunStop();
      JumpStart();
      
 
 
     }
     }
     
      if(Jumping == true){
      if(Input.GetButtonUp("up")){
      print ("up arrow key has been lifted");
      
      Ducking = true;
      JumpStop();
      RunStart();
     }
     }
     
     
      if(Ducking == true){
      if(Input.GetButtonDown("down")){
      print ("down arrow key is held down");
     
      Jumping = false;
      RunStop();
      DuckStart();
     
     }
     }
     
     if(Ducking == true){
     if(Input.GetButtonUp("down")){
     print ("down arrow key has been lifted");
     
     Jumping = true;
     DuckStop();
     RunStart();
     
     }
 
 }
 }
 
 
 
 
 
 function RunStart(){
     
     
     
     var Running  = Instantiate(Run, transform.position, transform.rotation);
     Running.transform.parent = transform;
 
 }
 
 function RunStop(){
 
     StopRunning = GameObject.Find("RunFull(Clone)"); 
     Destroy(StopRunning);
 
 }
 
 function DuckStart(){
     
     if(Ducking == true){
     var Ducking  = Instantiate(Duck, transform.position, transform.rotation);
     Ducking.transform.parent = transform;
 }
 }
 
 function DuckStop(){
     
     StopDucking = GameObject.Find("DuckFull(Clone)"); 
     Destroy(StopDucking);
 }
 
 function JumpStart(){
     
     if(Jumping == true){
     var Jumping  = Instantiate(Jump, transform.position, transform.rotation);
     Jumping.transform.parent = transform;
 }
 }
 
 function JumpStop(){
     StopJumping = GameObject.Find("JumpFull(Clone)"); 
     Destroy(StopJumping);
 }


I can't figure out how to get the more complicated button presses in there and also stop (namely the running frame) from cloning and instantiating more than once due to certain combinations of Up and Down being held/let go.

I've tried having all 3 prefabs of Running, Jumping and Ducking going at the same time and the buttons presses hide/show them but I couldn't get that to work...surely there must be a better way than having the players jump animation Instantiate EVERYTIME they need to jump?

Sorry this is long and may appear stupid but that's it...I know there's an easier way round this but I can't see it! any help would be great in making this simple thing run, thanks!

Comment
Add comment · Show 6
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 Adamcbrz · Aug 06, 2013 at 12:36 PM 0
Share

What are you Instantiate? $$anonymous$$odel's with animations or Sprites? This seems like a little weird way of accomplishing the goal either way. I can give you more details depending on your approach.

avatar image MSB · Aug 06, 2013 at 12:46 PM 0
Share

Again I feel as though this may be silly but...

The "Jump" and "Duck" instances are prefabs that hold a single 3D model each.

The "Running" is a prefab that holds lots of 3D models that loop to create an animation.


 function Start () {
 
 {
  for(i=0; i<=9999; i++)
  {
  
 var VFrame1clone  = Instantiate(VFrame1, transform.position, transform.rotation);
 VFrame1clone.transform.parent = transform;
 yield WaitForSeconds(delay);
 Destroy(VFrame1clone);
 
 var VFrame2clone  = Instantiate(VFrame2, transform.position, transform.rotation);
 VFrame2clone.transform.parent = transform;
 yield WaitForSeconds(delay);
 Destroy(VFrame2clone);
 
 //GOES ON 18 $$anonymous$$ORE FRA$$anonymous$$ES THEN LOOPS


Thanks for the comment!

avatar image Adamcbrz · Aug 06, 2013 at 01:14 PM 0
Share

That is terrible...no offense intended. Can you or some you know convert those to an animation in a maya or 3ds max?

avatar image nixcs2512 · Aug 06, 2013 at 01:19 PM 0
Share

Why don't you create animation for 3d model rather than do the way of 2D game - store lots of image(3d models in your case) for each frame.If you only need 2D game , so there are many documents about that, and you dont need any 3D model too.

avatar image Creator347 · Aug 06, 2013 at 01:24 PM 0
Share

you'd need animation as previous comments told you. You can try $$anonymous$$ecanim for smoother animation transitions, between running, jumping and ducking.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Why isn't my joystick code work ? 0 Answers

How to make a character run by alternately hitting two buttons? 3 Answers

Running straight 2 Answers

Running Chicken Controls 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