Character behavior

chongyunxiang

  • Posts: 249
I want to make my pet have a more natural behavior. I'm sure what I did is not the correct way, especially with all the randomness...
I want my pet to look left, right, then move a bit etc, all within the boundaries of the screen.

Is there a better way to do this?

Thanks!

JeffreyDriver

  • *
  • Posts: 2250
I can see an issue with your 'slide by' blocks as you are picking a random integer between 0 and 1. If it picks 0, your pet will teleport immediately.

Another issue you will have is that you don't have a way to ensure your pet doesn't go off screen, so you will need to check the X position. For instance, if your pet is too close to the left of the screen you need to make sure it won't try and go left again.

Your pet also seems to be constantly on the move. For a nice randomness, you might want your pet to do other things such as sit on the spot, lie down and nap, go to its food bowl etc.

chongyunxiang

  • Posts: 249
Thank! I've done some changes based on your suggestions. Now i'm working on getting it to play emoticons based on either random or events, but I can't figure out the steps behind it. As in I know the logic, like to trigger an event that draws the emoticon actor at the top (left/right) corner of the pet. But I was trying and it didn't work. I'm probably doing it wrong. Any help for this?

JeffreyDriver

  • *
  • Posts: 2250
I would create an emoticon actor when the scene loads, and give this actor every animation it needs.

When created, you can hide it, but when an event is triggered, switch the animation to whatever it needs to be and then show it. After 3 (or whatever) seconds, hide it.

chongyunxiang

  • Posts: 249
How do i attach the emoticon to the actor? I have an emoticon actor but the Draw functions don't seem to give me the options to create the emoticon. I tried creating an Actor Attribute, but can't find a way to link the actor to the pet. Sry if I'm a noob at this (bad at programming).

chongyunxiang

  • Posts: 249
The pet behavior is not working properly. The X axis limit doesn't seem to apply, then when it reaches the end, it somehow gets stuck and it doesn't move anymore. What's wrong with it?

JeffreyDriver

  • *
  • Posts: 2250
In your 'SetRandom' event, switch the greater/less than blocks.

As for referencing another actor, you can use the 'for each actor of type' block and assign it an actor attribute straight away than you can then refer to as another actor.

chongyunxiang

  • Posts: 249
By switching the more/less than, you mean like this?

chongyunxiang

  • Posts: 249
I feel so dumb, i could've just used the Create Actor block (which works well)...instead of finding ways to create attribute and Draw actor onto the scene! Now I just need to figure out how to make the emoticon follow the Pet because when it's create, it stays at the last known axis of the pet. Any ideas?

Luyren

  • *
  • Posts: 2289
I feel so dumb, i could've just used the Create Actor block (which works well)...instead of finding ways to create attribute and Draw actor onto the scene! Now I just need to figure out how to make the emoticon follow the Pet because when it's create, it stays at the last known axis of the pet. Any ideas?
Create an attribute of type "actor" and set it to "last created actor" immediately after you create your emoticon actor. You can then check if your attribute has value and if it is alive, and if it is, set its position to that of your player actor plus an offset.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

chongyunxiang

  • Posts: 249
Sry im a quite lost. I created an Actor attribute called Emoticon, and set it to Last Created Actor. But I can't find any blocks that checks the value of an attribute and which is the block that sets the position of the attribute to an Actor's position?

I tried the When Updating event and it was totally wrong, made a mistake there.

Luyren

  • *
  • Posts: 2289
But I can't find any blocks that checks the value of an attribute
Attributes > Functions. Remember To also check if the "actor" attribute is alive (Actors > Properties). That will prevent a crash if you try to set the position of an non-existent actor.

[...] and which is the block that sets the position of the attribute to an Actor's position?
Set X and Y positions under Actors > Position. Just drag you "actor" attribute into the actor slot of those blocks.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

chongyunxiang

  • Posts: 249
Thanks! The emoticon is now following the pet and have it appear at the top of the pet. I also included a function to kill the emoticon first, each time the emoticon is activated. This prevents multiple copies of the emoticon from being created. I've included the blocks of code that I've used in the attachment (ActorEvents_0.png) for those who are interested in it.

I've also had the same recurring problem with my pet movement behavior. It keeps moving past the axis that I set it to check, and then getting stuck at the edge of the screen. I don't want the pet to exit the screen and to stay within a boundary of the screen. Where did I go wrong?

Luyren

  • *
  • Posts: 2289
You have to put your axis check in an "Update" event.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

chongyunxiang

  • Posts: 249
You have to put your axis check in an "Update" event.

Under the Updating event, I set it to check the axis, then set a boolean for it. But now my pet doesn't move and I don't know what is wrong.