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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by phyce · Mar 21, 2013 at 10:07 PM · javascriptbooport

Porting Code from javascript to boo.

Hello. I've started watching a tutorial on youtube on how to make a 2d platformer using unity3d. http://www.youtube.com/watch?v=EW0phq6xoJk This is the link to the video. I've started port the js code provided in the description to boo, to practice and learn a bit about js, since I come from a python background. Here's the original code: http://db.tt/6Z1uSVUd

And here's my port to boo:

 import UnityEngine
 
 canControl = true
 
 spawnPoint = Transform()
 
 class PlatformerControllerMovement():
     walkSpeed = 3.0
     runSpeed = 10.0
     inAirControlAcceleration = 1.0
     gravity = 60.0
     maxFallSpeed = 20.0
     speedSmoothing = 5.0
     rotationSmoothing = 10.0
     direction = Vector3.zero
     [System.NonSerialized]
     verticalSpeed = 0.0
     [System.NonSerialized]
     speed = 0.0
     [System.NonSerialized]
     isMoving = false
     [System.NonSerialized]
     collisionFlags as CollisionFlags
     [System.NonSerialized]
     velocity = Vector3
     [System.NonSerialized]
     inAirVelocity = Vector3.zero
     [System.NonSerialized]
     hangTime = 0.0
 
 movement = PlatformControllerMovement()
 
 class PlatformerControllerJumping():
     enabled = true
     height = 1.0
     extraHeight = 4.1
     [System.NonSerialized]
     repeatTime = 0.05
     [System.NonSerialized]
     timeout = 0.15
     [System.NonSerialized]
     jumping = false
     [System.NonSerialized]
     reachedApex = false
     [System.NonSerialized]
     lastButtonTime = -10.0
     [System.NonSerialized]
     lastTime = -1.0
     [System.NonSerialized]
     var lastStartHeight = 0.0
 
 jump = PlatformerControllerJumping()
 controller = CharacterController()
 activePlatform = Transform()
 activeLocalPlatformPoint = Vector3()
 activeGlobalPlatformPoint = Vector3()
 lastPlatformVelocity = Vector3()
 areEmittersOn = false
 
 def Awake():
     movement.direction = transform.TransformDirection(Vector3.forward)
     controller = GetComponent(CharacterController)
     Spawn()
 
 def Spawn():
     movement.verticalSpeed = 0.0
     movement.speed = 0.0
     transform.position = spawnPoint.position
 
 def OnDeath():
     Spawn()
     
 def UpdateSmoothedMovementDirection():
     h = Input.GetAxisRaw("Horizontal")
     if canControl == false:
         h = 0.0
     movement.isMoving = Mathf.Abs(h)>0.1
     if movement.isMoving == true:
         movement.direction = Vector3(h, 0,0)
     if controller.isGrounded == true:
         curSmooth = movement.speedSmoothing * Time.deltaTime
         targetSpeed = Mathf.Min(Mathf.Abs(h), 1.0)
         if Input.GetButton("Fire2") == true and canControl == true:
             targetSpeed *= movement.runSpeed
         else:
             targetSpeed *= movement.walkSpeed
         movement.speed = Mathf.Lerp(movement.speed, targetSpeed, curSmooth)
         movement.hangTime = 0.0
     else:
         movement.hangTime += Time.deltaTime
         if movement.isMoving = true:
             movement.inAirVelocity += Vector3(Mathf.Sign(h), 0,0) * Time.deltaTime * movement.inAirControlAcceleration
 
 def FixedUpdate():
     transform.position.z = 0
 
 def ApplyJumping():
     if jump.lastTime + jump.repeatTime > Time.time:
         return
     if controller.isGrounded == true:
         if jump.enabled and Time.time < jump.lastButtonTime + jump.timeout:
             movement.verticalSpeed = CalculateJumpVerticalSpeed(jump.height)
             movement.inAirVelocity = lastPlatformVelocity
             SendMessage("DidJump", SendMessageOptions.DontRequireReceiver)
 
 def ApplyGravity():
     jumpButton = Input.GetButton("Jump")
     if canControl == false:
         jumpButton = false
     if jump.jumping == true and jump.reachedApex == false and movement.verticalSpeed <= 0.0
         jump.reachedApex = true
         SendMessage("DidJumpReacheApex", SendMessageOptions.DontRequireReceiver)
         extraPowerJump = jump.jumping == true and movement.verticalSpeed > 0.0 and jumpButton == true and transform.position.y < jump.lastStartHeight + jump.extraHeight and IsTouchingCeiling() == false
         if extraPowerJump == true:
             return
         elif controller.isGrounded == true:
             movement.verticalSpeed = -movement.gravity * Time.deltaTime
         else:
             movement.verticalSpeed -= movement.gravity * Time.deltaTime
         movement.verticalSpeed = Mathf.Max(movement.verticalSpeed, -movement.maxFallSpeed)
 
 def CalculateJumpVerticalSpeed(targetJumpHeight):
     return Mathf.Sqrt(2.0 * targetJumpHeight * movement.gravity)
 
 def DidJump()
     jump.jumping = true
     jump.reachedAped = false
     jump.lastTime = Time.time
     jump.lastStartHeight = transform.position.y
     jump.lastButtonTime = -10
     
 def UpdateEffects():
     wereEmittersOn = areEmittersOn
     areEmittersOn = jump.jumping and movement.verticalSpeed > 0.0
     
     if wereEmittersOn != areEmittersOn:
         for emitter in GetComponentsInChildren(ParticleEmitter):
             emitter.emit = areEmittersOn
 
 def Update():
     if Input.GetButtonDown("Jump") and canControl == true:
         jump.lastButtonTime = Time.time
 
     UpdateSmoothedMovementDirection()
     ApplyGravity()
     ApplyJumping()
     if activePlatform != null:
         newGlobalPlatformPoint = activePlatform.TransformPoint(activeLocalPlatformPoint)
         moveDiscance = (newGlobalPlatformPoint - activeGlobalPlatformPoint)
         transform.position = transform.position + moveDistance
         lastPlatformVelocity = (newGlobalPlatformPoint - activeGlobalPlatformPoint) / Time.deltaTime
     else:
         lastPlatformVelocity = Vector3.zero
     activePlatform = null
     lastPosition = transform.position
     currentMovementOffset = movement.direction * movement.speed + Vector3(0, movement.verticalSpeed, 0) + movement.inAirVelocity
     currentMovementOffset *=Time.deltaTime
     movement.collisionFlags = controller.Move(currentMovementOffset)
     movement.velocity = (transform.position - lastPosition) / Time.deltaTime
     if activePlaform != null:
         activeGlobalPlaftormPoint = transform.position
         activeLocalPlaformPoint = activePlatform.InverseTransformPoint(transform.position)
     if controller.isGrounded == true:
         movement.inAirVelocity = Vector3.zero
         if jump.jumping == true:
             jump.jumping = false
             SendMessage("DidLand", SendMessageOptions.DontRequireReceiver)
             jumpMoveDirection = movement.direction * movement.speed + movement.inAirVelocity
             if jumpMoveDirection.sqrMagniture > 0.01:
                 movement.direction = jumpMoveDirection.normalized
     UpdateEffects()
 
 def OnControllerColliderHit(hit = ControllerColliderHit):
     if hit.moveDirection.y > 0.01:
         return
     if hit.moveDirection.y < -0.9 and hit.normal.y > 0.9:
         activePlatform = hit.collider.transform
 
 def GetSpeed():
     return movement.speed
 
 def GetVelocity():
     return movement.velocity
 
 def IsMoving():
     return movement.isMoving
 
 def IsJumping():
     jump.jumping
 
 def IsTouchingCeiling():
     return movement.collisionFlags != 0 and CollisionFlags.CollidedAbove != 0
 
 def GetDirection():
     return movement.direction
 
 def GetHangTime():
     movement.hangTime
 
 def Reset():
     gameObject.tag = "Player"
 
 def SetControllable(controllable):
     canControl = controllable
 
 [RequireComponent(CharacterController)]
 [AddComponentMenu("2D Platformer/Platformer Controller")]

The error I get when trying to run the game:

Assets/Scripts/PlatformerController.boo(7,1): BCE0044: expecting "EOF", found class.

I can't seem to realize what does the error mean. This is the first time I'm working with Unity3d and boo, I'd really appreciate if anyone could help me.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Mar 21, 2013 at 10:34 PM

Like C#, you need to explicitly declare a class that extends MonoBehaviour, if you're going to use MonoBehaviour functions like Update/Reset/etc.

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

11 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

Related Questions

I can't open boo or js scripts in Monodevelop with a default install? 3 Answers

Why not Boo? 1 Answer

Audio not playing [Fixed] 1 Answer

An instance of type 'UnityEngine.BoxCollider2D' is... 1 Answer

MasterServer errors 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