- Home /
Boo & Collision
Pardon the terrible username! It'll be fixed, given whenever Unity support gets around to it. Initially when I was lurking I didn't care too much what the username was and they accepted this. Bwaha.
I love Python and therefore most relate to Boo, so I've been using that, but the documentation is sub-par. This is also my first experience with Unity in general, so I hope you'll bear with me. I'm trying to get collision to work, so as a test I'm trying to get an upper boundary to work, however it does not seem to do what I want. The boundary is already in the appropriate spot, however the blocks go right through each other! I've tried every combination of triggers set to on & off, OnTriggerEnter and OnCollisionEnter used. I wonder where I could be going wrong?
This has always been a stumbling block for me when I'm building a game so I'd at least like to get it working. This is my best shot! Please teach this poor newbie.
This is the player script:
import UnityEngine
class player_movement (MonoBehaviour):
def Start ():
pass
##How the hell do I make this public??
##This does not work:
#public reachedtop = false
def Update ():
/ These next variables can only be declared as Vector2 variables if they identify as a 'float' apparently... however I have only found these 3 float-like types: single, double and decimal. None seemed to work. /
#vecspeedup = 0 # as decimal = 0.0
#vecspeeddown = 0 # as decimal = 0.0
#vecspeedleft = 0 # as decimal = 0.0
#vecspeedright = 0 # as decimal = 0.0
speed0 = 0 # as decimal = 0.0
speed1 = 0 # as decimal = 0.0
reachedtop = false
def OnTriggerEnter(c as Collision):
if c.gameObject.CompareTag("top"):
reachedtop = true
##deltaTime keeps it in the same relative time of a locked framerate
##Look up how to specifically obtain 60fps
speed0 = (0.0 * Time.deltaTime)
speed1 = (400.0 * Time.deltaTime)
##Ship movement, GetKey, GetKeyDown, GetKeyUp...
##Also, use KeyCode.whatever to access input directly
if Input.GetKey(KeyCode.UpArrow):
if reachedtop == true:
vecspeedup = Vector2(0,0) * speed0
else:
vecspeedup = Vector2(0,1) * speed1
transform.Translate(vecspeedup)
elif Input.GetKey(KeyCode.DownArrow):
##other buttons...
##END
Error output: Boo Compiler version 0.9.5.5 (2.0 (Visual Studio built mono))
-----CompilerOutput:-stderr----------
WARNING: booc is not using the Boo.Lang.Compiler.dll next to booc.exe. Using 'C:\\Program Files\Unity\Editor\Data\Mono\lib\mono\unity\Boo.Lang.Compiler.dll' instead of 'C:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity\Boo.Lang.Compiler.dll'. You may need to remove boo dlls from the GAC using gacutil or Mscorcfg.
Assets/Project/Scripts/player_movement.boo(21,9): BCW0003: WARNING: Unused local variable 'OnTriggerEnter'.
1 warning(s).
How do I get public to work in Boo? How do I get those collisions to activate my code? The warning seems to be saying that OnTriggerEnter is an unused variable. That must not be right. How would that be corrected? Is it particularly different between onTrigger and onCollision? ...Is the compiler producing an error that suggests I manually fix it?
I greatly appreciate all valuable answers!
Answer by Kevin Harris · Oct 07, 2012 at 12:43 PM
Public works as in C#:
public myPublicVariable as int myPrivateVariable as int public def MyPublicFunction(): # Do something def MyPrivateFunction(): # Do something else
single is the Boo equivalent of float.
Declaring Vector2 variables is the same as declaring other variable types. The following are equivalent:
vecspeedup as Vector2 vecspeeddown as Vector2 = Vector2(0.0, 0.0) vecspeedleft = Vector2(0.0, 0.0)
Your OnTriggerEnter method is using a Collision instead of a Collider object. See the documentation, which also has a Boo example.
Boo is case sensitive, so OnTriggerEnter and onTriggerEnter are different.
Your collision issues may result from a few issues. First, do your objects have collider components? Second, do the objects that are supposed to collide agree with the collision action matrix? Third, are the objects on layers that collide?
You are defining OnTriggerEnter inside Update. It should be declared as a distinct function, meaning that the function definitions should align:
def Update(): # Your update statements & expressions def OnTriggerEnter(c as Collider): # Your collision handling
I would upvote you if I could, it says I cannot for some reason... Here are my followups:
.1. Ah, got it to work. It was inside the method, when it should have been directly within the class.
.2. Indeed, I was able to correct this one. I declare the variables as empty Vector2s now.
.3. See 2 & thank you for the examples.
.4. Thank you. I would not have spotted that, silly mistake on my part! I must have misread some instructions.
.5. Oh? That's disappointing. I don't recall Python being case sensitive... I leaned towards being verbose with the syntax rather than use any specific case. It is a pity that Boo works differently here. I'll get the hang of it, but I need to know: are there any other case mistakes I might fall for in the syntax or a page I can refer?
.6a. Yes, definitely
.6b. I have observed this list... I do not want any physics, I want to handle collision code and physics manually. For the most part, when I use Vector2/3 changes they should still operate normally. The collision boxes will activate and execute various code depending on tags. They are all just boxes, nothing complicated. Do I want them all to be "$$anonymous$$inematic Rigidbody Trigger Colliders"? Those seem to be the only ones that register collisions without calculating the physics in Unity.
.6c. Yes, definitely
.7. Fixed, thank you very much. It still does not seem to change the boolean 'reachedtop' from within update though... that is what I need to do. How would I use that method within the Update() method?
Re 5: The main documentation wiki for Boo should help with general syntax; for Unity-specific functions, the script reference is valuable. There's also a page on Boo for Python users.
Re 6b: From the collision matrix, it looks like two kinematic rigidbody colliders won't cause trigger messages to be sent. You could use two kinematic rigidbody colliders for triggers, but this may be a bit much depending on what you're doing; otherwise a combination of static colliders and rigidbody colliders may work a bit better for you.
Re 7: This is likely related to 6b and the triggers not generating a valid collision. Unity will automatically call the collision functions when the colliders are correctly configured. It can be tricky figuring out how to set things up initially, but it should save you time in the long run.
And if you're happy with an answer, there should be a check box under up- and down-voting to accept. Hope this helps–––good luck!
Thank you for the Gotchas for Python users page.
I settled on using kinematic (because if I didn't and still locked the axis' that I needed, it would still react to the physics by bouncing off and expressing inertia, which I am avoiding) rigidbody trigger colliders. I want them all to be the same, yet seperated by tags or maybe a manually implemented identity. Rigidbody + triggers seems to be the only appropriate answer for those needs according to the matrix.
Also, I got it all working correctly! It's responding to my code. Now I'm off to figure out how to send messages so I have more options for controlling all the variables. Thank you very much for your help.
Your answer
Follow this Question
Related Questions
Play sound on collision doesn't work 1 Answer
Smooth movement for the block upon player collision,Smooth box movement 0 Answers
Help with collisions and destroy please 1 Answer
Cannot get collision to do anything 1 Answer
Find cardinal direction of collision based on 2D Cartesian coordinates 1 Answer