class TwoDPlatformController ( MonoBehaviour ):
public walkSpeed as single = 6.0F
public runSpeed as single = 10.0F
public jumpSpeed as single = 8.0F
public gravity as single = 20.0F
public doubleJump as bool = true
public midAirJumps as int = 2
private moveDirection as Vector3 = Vector3.zero
private curNumJump as int = 1
private controller as CharacterController
def Update():
PlayerMovement()
HandleEvents()
def PlayerMovement ():
controller = GetComponent(CharacterController)
// While character is grounded allow to jump and horizontal movement
// Player is restricted in jump movement. One way jump if double jump disabled
if controller.isGrounded:
moveDirection = Vector3( -1 * Input.GetAxis('Horizontal')*walkSpeed, 0, 0 )
SingleJump()
//Player is in the air
else:
ExtraJump()
ApplyGravityForce()
controller.Move( moveDirection * Time.deltaTime )
def SingleJump ():
// Immediately present number of allowed mid air jumps when landed
// Allow player to jump
curNumJump = 1
if Input.GetButton( 'Jump' ) or Input.GetKeyDown( 'w' ):
moveDirection.y = jumpSpeed
def ExtraJump ():
// Allow player the capability to jump multiple times in mid air
// Number of times is based on 'midAirJumps'
// Once limit is reach player must land before jumping again
// When jumping horizontal movement is unlocked for that jump then it will be locked again
if (Input.GetButtonDown( 'Jump' ) or Input.GetKeyDown( 'w' )) and doubleJump:
//Player has not met his extra jumping limit
if curNumJump < midAirJumps:
moveDirection = Vector3( -1 * Input.GetAxis('Horizontal')*walkSpeed, 0, 0 )
moveDirection.y = jumpSpeed
curNumJump += 1
def ApplyGravityForce ():
moveDirection.y -= ( gravity * Time.deltaTime )
def HandleEvents ():
// Events taken place are of action types: shooting, special attacks, interactable object, etc
pass
How is my programming format
Hi Cdrandin,
First of all let me tell you I don't program unity but do program python, c#, c++, etc. Looking at the format I personally think it looks really clean. Only thing I would change myself (if possible) is put the description of the function above the function. Also I am missing a simple outline for the class (meaning a bit of comments explaining what this class is for).
As for the rest of the code I think it looks pretty nice.
With kind regards,
StaticCUbe
I'm not personally for spaces before or after brackets, but at a high level I find the code to be actually readable. The comments are useful and relevant, it's clean. Maybe try and be a bit more consistent with newlines.
Looks good, I would however recommend learning something more powerful than VB if you expect to make responsive high paced games that those of us with older computers (You know the majority of your potential players) can play. Yes the obvious functions are always better to have.
Looks good, I would however recommend learning something more powerful than VB if you expect to make responsive high paced games that those of us with older computers (You know the majority of your potential players) can play. Yes the obvious functions are always better to have.That's not VB, I think it's Boo.
Looks good, I would however recommend learning something more powerful than VB if you expect to make responsive high paced games that those of us with older computers (You know the majority of your potential players) can play. Yes the obvious functions are always better to have.That's not VB, I think it's Boo.
Well that might just negate my comment. If it's a scripting language particular to the engine than it probably is among the best performance you would get with the entire kit. Just noticed the lack of ; and {} which immediately makes me thing VB or even worse Python :-o
I personally think it looks clean. I used to smash all of my code into one place (e.g. all logic in the Update() function in Unity) and use "folding comments" to organize it, but now I'm starting to prefer separating them into functions and applying that to all my latest code.
I'm not sure if this actually works with Boo, but if you're using the text editor that comes with Unity, called UniSciTE, then it allows you to make "folding comments" like so:
//{Movement:
//Movement code goes here
//}
//{Jumping:
//Jumping code goes here
//}
These are like 'regions'. I'm not sure if regions are applicable to other languages/IDEs, because I've only used them in Visual Studio C#, but I know they don't work in UniSciTE.
Anyway, they make it so that you can fold the selection, and hide everything but the first comment with the starting brace in it, like "//Jumping:"
I think there are a lot of people who are against the idea of folding up your code with regions (or "folding comments"), but I just wanted to let you know about them if you wanted to use them. They're pretty much the only way to fold stuff up in UniSciTE manually, without that something being a function, class, etc.
Anyway, as I said, you might not want to use this technique and it might not even work with Boo, but too bad because knowing about it is already taking up space in your brain!
Very nice but comment your functions, 6 months from now you wont remember what you wrote so u need to leave your self notes or someone else notes.