Topic: setCurrentBehavior

Hello, I would want to question about setCurrentBehavior.

When I set my robot to look at the person when he is in range of the robots sensor (a cylinder) it doesn't look that way.

This is my script:

if isCollisionBetween(player,sensor) then

        setBehaviorVariable(robot, 0, "target", "player")

end

Re: setCurrentBehavior

I think that You has to disable the behaviour when the person goes away from the sensor.

if isCollisionBetween(player,sensor) then
      --code to enable behaviour
else
      --code to disable behaviour
end

Re: setCurrentBehavior

The setBehaviorVariable code is right, maybe the problem comes from the collision detection ?

Re: setCurrentBehavior

Hm, I wrote it out just:

setBehaviorVariable(robot, 0, "target", "player")

In the console but nothing happened.

Last edited by Pär (2013-01-15 19:18:29)

Re: setCurrentBehavior

To make characters look at another entity with the LookAt behavior (like the zombie in This example) personally i have to export the models in that position (or something similiar) :

PunBB bbcode test

Then if i need to move them ; addCentralForce(object, {0, 0, -1}, "local")

That's a bit weird but it works =p

Re: setCurrentBehavior

I understand. smile Well, there is no problem if I set my player to lookAt in maratis and then execute it. But if I try to write it out in the console then nothing happens. And my robot is moving already, so maybe a bug?

Thanks for the reply.

Last edited by Pär (2013-01-15 22:35:16)

Re: setCurrentBehavior

Vegas : it's because the look at is using the Z axis (the one originally used by camera),
but to not have to re-export the character, use an invisible box and link your character to it.

Par : I'm not sure I understand what you mean.
Check first if the collision is detected, then check if your player name is "player" in the editor,
and that sensor is having a collision shape (in ghost mode I guess).

Re: setCurrentBehavior

Ok, my playername is player in the editor. And my sensor has a collisionshape in ghost mode.

Oh, there is collision detected. smile

I write: setBehaviorVariable(trylare, 0, "target", "player") setBehaviorVariable(trylare_model, 0, "target", "player") in function onSceneUpdate() without any if statements but nothing happens, what's wrong?

Last edited by Pär (2013-01-15 22:32:26)

Re: setCurrentBehavior

Did you add a LookAt behavior on your trylare model in the editor ?
and is it the first behavior in the list (0 in the function access the first behavior of the object)

if trylare having a parent it is linked to ? a parent link might conflict with the look-at.

Re: setCurrentBehavior

Ahhh I see I was wondering why when I was trying to do a billboarding deal with my plants and grass it got all weird.

Re: setCurrentBehavior

Thank you Anael, I wasn't aware that I needed to set my model to lookAt already IN the editor, once again thanks. smile

Re: setCurrentBehavior

yes setBehaviorVariable and getBehaviorVariable are only there to access a behavior variables that is already there.