Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (TipmyPip, AndrewAMD, NewbieZorro), 16,055 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
Yet another question.. #366875
04/07/11 19:35
04/07/11 19:35
Joined: Mar 2010
Posts: 56
Hertfordshire, England
Panda_Dude Offline OP
Junior Member
Panda_Dude  Offline OP
Junior Member

Joined: Mar 2010
Posts: 56
Hertfordshire, England
I'm starting to get a bit irritated at how I have to ask so many questions, but I've search in the AUM articles and in the forum but I can't find an answer. How can I make a character fire a projectile? I'm making a 2d game at the moment and I need the character to be able to fire... Help?
Thanks for any advice tongue

Re: Yet another question.. [Re: Panda_Dude] #366879
04/07/11 19:49
04/07/11 19:49
Joined: Dec 2008
Posts: 1,660
North America
Redeemer Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
To create an entity (a bullet, in your case) at runtime, you must use the ent_create() function. Here's an example.

Code:
var allow_fire = 1;

action bullet_act()
{
  while( my )
  {
    // we must use IGNORE_PUSH to prevent the bullet from getting stuck in the player

    c_move( my, vector( 32*time_step, 0, 0 ), nullvector, IGNORE_PASSABLE | IGNORE_PUSH );

    if( trace_hit ) // this is true if I hit an object
      ent_remove(my);

    wait(1);
  }
}

action player_act()
{
  my.push = -1;
  while( my )
  {
    if( key_space && allow_fire ) // if key_space is pressed...
    {
      your = ent_create( "bullet.mdl", my.x, bullet_act ); // fire a bullet

      vec_set( your.pan, my.pan ); // set your angles

      allow_fire = 0; // this prevents multiple bullets from appearing whenever the space bar is held down
    }
    if( !key_space ) allow_fire = 1;

    wait(1);
  }
}



Last edited by Redeemer; 04/07/11 19:50.

Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: Yet another question.. [Re: Redeemer] #366888
04/07/11 20:18
04/07/11 20:18
Joined: Mar 2010
Posts: 56
Hertfordshire, England
Panda_Dude Offline OP
Junior Member
Panda_Dude  Offline OP
Junior Member

Joined: Mar 2010
Posts: 56
Hertfordshire, England
Ok thanks, that works smile
One thing though - if I fire while moving the character, the character jolts a bit. How can I get rid of this? Also, without two lines of code, the player carries on moving unless you press a key to slow it down. My question is can you write these two lines of code shorter with some kind of 'or' thing?
Code:
if (!key_cuu) movement = 0;
    if (!key_cud) movement = 0;



Re: Yet another question.. [Re: Panda_Dude] #366901
04/07/11 21:01
04/07/11 21:01
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline
Expert
FoxHound  Offline
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
if((!key_cuu) && (!key_cud))
{

}


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: Yet another question.. [Re: FoxHound] #366936
04/08/11 05:12
04/08/11 05:12
Joined: Mar 2010
Posts: 56
Hertfordshire, England
Panda_Dude Offline OP
Junior Member
Panda_Dude  Offline OP
Junior Member

Joined: Mar 2010
Posts: 56
Hertfordshire, England
hmmm... Thanks. That was more obvious than I had expected. smile
How would I make enemies move towards the player? Could I use path_set in the enemy action or is there an easir way?

Last edited by Panda_Dude; 04/08/11 05:18.
Re: Yet another question.. [Re: Panda_Dude] #366978
04/08/11 13:52
04/08/11 13:52
Joined: Dec 2008
Posts: 1,660
North America
Redeemer Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
path_set() is used to attach an entity to a path that has already been created in WED, so it won't help you here.

To make an enemy follow a player, you'll need to create some artificial intelligence. The simplest way to accomplish this is to create a state machine, like this:

Code:
function state_wait()
{
  // wait!
}

function state_hunt()
{
  // hunt!
}

function state_attack()
{
  // attack!
}

function state_die()
{
  // die!
}

action enemy_act()
{
  my.state = 1; // start in wait mode.

  while( my )
  {
    switch( my.state ) // change my behavior based on my.state
    {
      case 1: state_wait(); break;
      case 2: state_hunt(); break;
      case 3: state_attack(); break;
      case 4: state_die(); break;
    }

    wait(1);
  }
}



As you can see, by simply changing my.state in enemy_act I can completely change the behavior of the enemy. When the individual states are programmed to change the entity's behavior based on certain criteria, this whole system becomes a state machine.

Obviously you'll need to fill out the various states I've set up here, or create some new ones to fulfill your needs. I persoanlly suggest you set up your state machine like this:


State wait: stand still. Look for the player with c_scan and/or c_trace. If he is found, my.state = 2. If my health <= 0, my.state = 4.

State hunt: move towards the player. Check to see if he is in range to be attacked. If he is, my.state = 3. If my health <= 0, my.state = 4.

State attack: wait a second. shoot at the player. Switch back to state 3. If my health <= 0, my.state = 4.

State die: play die animation, then disappear.


Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: Yet another question.. [Re: Redeemer] #366987
04/08/11 14:58
04/08/11 14:58
Joined: Mar 2010
Posts: 56
Hertfordshire, England
Panda_Dude Offline OP
Junior Member
Panda_Dude  Offline OP
Junior Member

Joined: Mar 2010
Posts: 56
Hertfordshire, England
Ok thank you! This is helpful. I am in the process of learning this, but I've put in the my.state = 1; line in the enemy action and when I go to run it it says "'state' : is not a member of 'ENTITY'". What does this mean?

Re: Yet another question.. [Re: Panda_Dude] #367010
04/08/11 18:50
04/08/11 18:50
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline
Expert
FoxHound  Offline
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
look at how to define skills in the manual. That manual and the AUM were a lot of help when I first started out. A lot of problems will seem very obvious once solved.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: Yet another question.. [Re: FoxHound] #367012
04/08/11 19:02
04/08/11 19:02
Joined: Mar 2010
Posts: 56
Hertfordshire, England
Panda_Dude Offline OP
Junior Member
Panda_Dude  Offline OP
Junior Member

Joined: Mar 2010
Posts: 56
Hertfordshire, England
do you have to do
Code:
#define STATE     skill1

?
I can't seem to find anything to do with defining skills. It just seems so extensive; I don't know where to look.

Re: Yet another question.. [Re: Panda_Dude] #367015
04/08/11 19:17
04/08/11 19:17
Joined: Mar 2010
Posts: 56
Hertfordshire, England
Panda_Dude Offline OP
Junior Member
Panda_Dude  Offline OP
Junior Member

Joined: Mar 2010
Posts: 56
Hertfordshire, England
I found skill and #define in the manual but I still don't understand...

Page 1 of 5 1 2 3 4 5

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1