- Home /
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!
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.
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!
That is terrible...no offense intended. Can you or some you know convert those to an animation in a maya or 3ds max?
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.
you'd need animation as previous comments told you. You can try $$anonymous$$ecanim for smoother animation transitions, between running, jumping and ducking.
Your answer
Follow this Question
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