I have been trying the tutorials listed on the defold dashboard, and everything works fine except for inputs. None of them are ever registered and my objects can never move when I press keys on my keyboard. I have followed the tutorials exactly, copying the code. I’m really not sure what to do. Thanks
There are a few things to check. First make sure that you have the input bindings set up correctly. Compare the file you have with the screenshot.
It that looks ok, you can move on to “hero.script”.
The first thing that happens is that the script tells the engine that input should be forwarded to the hero game object. That is done in init():
function init(self)
-- this tells the engine to send input to on_input() in this script
msg.post(".", "acquire_input_focus")
...
Note that the “.” denotes the current game object, which is the game object that has this script added as a script component. Make sure you got the dot right and the spelling of “acquire_input_focus”.
Also check that the game object “hero.go” contains a script component that points to “hero.script”. Without that the script won’t run at all.
If you got this right can you please post your script code and we’ll have a look?
M
You wouldn’t believe, I had not added the scripts in. I feel pretty dumb now. Thanks a lot for the quick reply, I appreciate it a lot!
~ Kent
No worries. I’ve made that mistake many times myself.
I have the same issue… except I have added the script to hero.go
I checked the init with the focus code is also called
function init(self)
print("init hero")
-- this tells the engine to send input to on_input() in this script
msg.post(".", "acquire_input_focus")
-- save the starting position
self.position = go.get_position()
-- keep track of movement vector and if there is ground contact
self.velocity = vmath.vector3(0, 0, 0)
self.ground_contact = false
end
edit:
it looks like my problem is in the collision code:
i print out the value of ground_contact
in the hero update and it goes false, for no apparent reason, when the character is just running along the ground
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact true
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact false
DEBUG:SCRIPT: self.ground_contact false
I fixed my self.ground_contact
issue: I had to make hero’s collision object’s Type: Kinematic
… then it started working… Must’ve missed that step
Correct, in order for you to manually manipulate positions and resolve collisions you need the collision object to be of type Kinematic. Read more about the different types here: http://www.defold.com/doc/physics#_collision_objects
Thanks a lot this solve my problem, I have a misspelled error in the msg.post parameter.