BSL
B-B-B-BLAMM!!!
Ramses does as well I think.
Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!
You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PlayerPhysics))]
public class PlayerController : MonoBehaviour {
//Player Handling
public float gravity = 20;
public float walkSpeed = 10.0f;
public float runSpeed = 20.0f;
public float acceleration = 30.0f;
public float jumpHeight = 12.0f;
public float jumpAirTime = 0f;
public float jumpMaxAirTime = 0.2f;
public float timeOffGround = 0f;
private float currentSpeed;
private float targetSpeed;
private Vector2 amountToMove;
//jumping stuff
private bool hasJumped = false;
private bool falling = false;
//sloppy double jump stuff
private bool djump = true; //This must be set to true or false to enable double jump; set to true on item pickup or the like for ingame toggle.
public bool djumpused = true; //checks whether or not the jump has been used; set to true to any spawn off the ground
//will not result in the ability to double jump
private PlayerPhysics playerPhysics;
void Start ()
{
playerPhysics = GetComponent<PlayerPhysics>();
}
void Update ()
{
// Reset acceleration upon collision
if (playerPhysics.movementStopped)
{
targetSpeed = 0;
currentSpeed = 0;
}
//JUMPING and the like starts here
if (playerPhysics.grounded)
{
amountToMove.y = 0;
timeOffGround = 0;
djumpused = false;
hasJumped = false;
falling = false;
//Jump
if (Input.GetKeyDown(KeyCode.Space)) // If jump is pressed
{
jumpAirTime = jumpMaxAirTime; //Start jump
jumpAirTime -= Time.deltaTime; //Timer decreases
}
if (amountToMove.y == 0 && Input.GetKeyDown (KeyCode.Space) && jumpAirTime > 0) //If you are jumping
{
amountToMove.y = jumpHeight; //jumping force!
//jumpAirTime -= Time.deltaTime; //Timer decreases... useless?
}
else //when you are not jumping, just falling
{
jumpAirTime = 0;
}
}
if (Input.GetKeyUp(KeyCode.Space) && hasJumped == false && falling == true) //Jump is released
{
jumpAirTime = 0;
amountToMove.y = 0-gravity * Time.deltaTime; //this part stop momentum, but also causes gravity to stop...
hasJumped = true;
}
if (Input.GetKeyDown (KeyCode.Space) && djumpused == false && !playerPhysics.grounded)
{
amountToMove.y = jumpHeight;
djumpused = true;
}
else //gravity takes over at this point
{
falling = true;
}
//JUMPING END
if (Input.GetKeyDown (KeyCode.J))
{
GameObject Bullet = (GameObject)Instantiate(Resources.Load("Bullet"));
}
//Input and Running
float speed = (Input.GetButton ("Run"))?runSpeed:walkSpeed;
targetSpeed = Input.GetAxisRaw("Horizontal") * speed;
currentSpeed = IncrementTowards(currentSpeed, targetSpeed,acceleration);
amountToMove.x = currentSpeed;
amountToMove.y -= gravity * Time.deltaTime; //this makes you go down! :D
playerPhysics.Move(amountToMove*Time.deltaTime);
}
// Increase n towards target by speed
private float IncrementTowards(float n, float target, float a)
{
if (n == target)
{
return n;
}
else
{
float dir = Mathf.Sign (target - n); //must n be increased or decreainsed to get closer to target
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign (target-n))? n: target; //if n has increased over target then return target, otherwise return n. The ? n: is a shorthand if statement.
}
}
}
You want them to be able to jump / double jump while falling yeah ?I'm having trouble getting variable height jumping to work (there's a slight hover due to how I hacked it together so far).
if (Input.GetKeyUp(KeyCode.Space) && hasJumped == false && falling == true) //Jump is released
{
jumpAirTime = 0;
amountToMove.y = 0-gravity * Time.deltaTime; //this part stop momentum, but also causes gravity to stop...
hasJumped = true;
}
declineRate will represent the amount of space they decline over x seconds(their falling rate of momentum in a sense) until they hit the next patch of terrain under/beside them/above them, or until they haven't moved upward/ to a equal position as they were previously in for x seconds (maybe something like 1 s). Would set your jumpHeight to 0, and your amount to move would be amountToMove.y = declineRate * Time.deltaTime; // your falling force if they have moved downward.
Maybe in retrospect you could have a "Jumping" function (which has your jump released logic), and a "Falling" function, that way you could just call the falling function and return some significant variable to avoid needless clutter.
Yeah, I just don't know how to accurately really check current velocity on the y axis without making it too hackey. I could figure it out by typing a bunch of **** into the code but it'd be ugly and I'm taking this slow.
That is my current attempt, I just don't know how to properly identify the "Falling" function. I guess velocity == 0 && grounded == false, I'll have to tinker.
But seriously, if either of you guys want to make a video game send me a PM and I'll send you a GDD with the concept package. I'm going to be putting together a team in the coming months and funding the entire process myself then splitting any future profits amongst the team. I unfortunately only have $10k budgeted to spend on the project over a 2-3 year period so I can't even begin to afford to hire a fulltime team.
for swissSign-ups for Fire Emblem: Awakening mafia are go!Quick pitch: set-up is pretty unconventional, has elements of BIM in addition to several other things. It's a closed set-up, but the game isn't really going to be about traditional power roles as much as it will be about the mechanics, and the mechanics will be made known to everyone before the game begins (in fact, I may edit this post to include as brief of a summary as I can give in the near future).With all of that said, the game isn't going to be super complex a'laanything Nabe doesKoopa vs. Kefka nor super reliant on story flavor a'la Golden Sun mafia. It's basically just a BIM game with some (hopefully fun and interesting) twists.
Does someone want to hydra for a game? I don't care which one
RanjamaruRajmarru
Ranjarru
Ramma-Jamma