Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
3 registered members (Martin_HH, steyr, alibaba), 509 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Flying dragon move backward [Re: Realspawn] #455202
10/13/15 08:35
10/13/15 08:35
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Originally Posted By: Realspawn
perhaps placing a certain distance between the dragon
and the player pointer that allways have to be the same
so it flies with player and player can never walk go
past it or in this case keep turning to the player.
It uses no reverse it keeps the dragon directed at
the player laugh it still can shoot fireballs while its flying

Code:
#define idle 1
#define following 2
#define dead 3
#define status skill1
action my_enemy() // attach this action to your enemies
{
while (!hero) {wait (1);}
var idle_percentage = 0;
var run_percentage = 0;
VECTOR temp;
set (my, POLYGON); // use accurate collision detection
my.status = idle; // that's the same thing with my.skill1 = 1; (really!)
vec_set (temp.x, my.x); // trace 10,000 quants below the player
temp.z -= 10000;
my.z -= c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 20; // play with 20
while (my.status != dead) // this loop will run for as long as my.skill1 isn't equal to 3
{
vec_set (temp.x, my.x); // trace 10,000 quants below the player
temp.z -= 10000;
temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 20; // play with 20
if (my.status == idle) // hanging around?
{
ent_animate(my, "stand", idle_percentage, ANM_CYCLE); // play the "stand" aka idle animation
idle_percentage += 3 * time_step; // "3" controls the animation speed
if (vec_dist (hero.x, my.x) < 1000) // the player has come too close?
{
// scanned in the direction of the pan angle and detected the player?
if ((c_scan(my.x, my.pan, vector(120, 60, 1000), IGNORE_ME) > 0) && (you == hero))
{
my.status = following; // then attack the player even if it hasn't fired at the enemy yet
}
}
}
if (my.status == following) // shooting at the player?
{
vec_set(temp, hero.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan, temp); // turn the enemy towards the player
if (vec_dist (hero.x, my.x) > 100) // the distance between player and enemy is bigger than 100 quants?
{
c_move (my, vector(10 * time_step, 0, temp.z), nullvector, GLIDE); // move towards the player
ent_animate(my, "run", run_percentage, ANM_CYCLE); // play the "run" animation
run_percentage += 6 * time_step; // "6" controls the animation speed, using normal animation
}
if (vec_dist (hero.x, my.x) < 90) // the distance between player and enemy is smaller than 90 quants?
{
c_move (my, vector(-10 * time_step, 0, temp.z), nullvector, GLIDE); // move away from the player
ent_animate(my, "run", run_percentage, ANM_CYCLE); // play the "run" animation
run_percentage -= 6 * time_step; // "6" controls the animation speed, using a reversed animation
}
if (vec_dist (hero.x, my.x) > 500) // the player has moved far away from the enemy?
{
my.status = idle; // then switch to "idle"
}
}
wait (1);
}
set (my, PASSABLE); // allow the player to pass through the corpse now
}





here is a clip that shows it in action you can make it use any animation or function you want. https://youtu.be/eQzcIWnrJs0

Thank you Realspawn for your advice. I took your coding concept, and adapted it to my code. It seems to work pretty well. Thank you again.

Re: Flying dragon move backward [Re: Ruben] #455213
10/13/15 14:24
10/13/15 14:24
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline

Expert
Realspawn  Offline

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
Good to hear sometimes you can work around it by using a script
that might not be the first thing you think off but does the trick anyway laugh


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Flying dragon move backward [Re: Realspawn] #455218
10/13/15 17:15
10/13/15 17:15

M
Malice
Unregistered
Malice
Unregistered
M



@Wjbender "result" is internally owned. But true, you should ways check the return of the scan. Also in this case the scan is use flag2 to detect the player only, but in other cases it would trigger on any ent and set "result" and "you" to the closest ent.

Quote:
Returns:
Distance to closest object found, or 0 if no object was found.
Modifies:
you -- Pointer to the closest detected entity.
result -- Distance to the closest detected object.
target -- Position of the closest detected object.
bounce -- Direction to the closest detected camera position.
tex_color -- Color of the closest detected static light.


Using the internal result
Code:
result =0;
c_scan(....)
if(result)


Using a var or skill
Code:
my.skill90=0;
my.skill90=c_scan(....)
if(my.skill90)


Using all of them


Code:
my.skill90=c_scan(.....);
if(my.skill90 == result && my.skill90 != 0)
{
  if(you ==t_pointer)
   {
     if(vec_dist(my.x, traget.x) < num_for_range)
     // OR if(result < num_for_range)
      { 

        Do actions....


Re: Flying dragon move backward [Re: ] #455224
10/13/15 17:56
10/13/15 17:56

M
Malice
Unregistered
Malice
Unregistered
M



In my code above I changed the scan dist, however you could use a single set dist and many trigger lengths.

Code:
var dist_backup = 200;
var dist_hover = 400;
var dist_chase = 1000;
var dist_wait = 1500;
var dist_max_scan = 2000;

my.skill90=0;
my.skill90 = c_scan(my.x,my.pan,vector(360,0,dist_max_scan), FLAGS_HERE);
if(my.skill90 && you == player)
{
  if(result < 200)
  my.STATE = ST_BACK_UP;
  //if(result < dist_backup)
  //my.STATE = ST_BACK_UP;
  if(result <400 && result > 200) 
  my.STATE = ST_HOVER; 
  // if(result <dist_hover && result > dist_backup) 
  // my.STATE = ST_HOVER; 
  if(result < 1000 && result > 400)
  my.STATE = ST_CHASE;
  // if(result < dist_chase && result > dist_hover)
  // my.STATE = ST_CHASE;
  if(result < 1500 && result > 1000)
  my.STATE = ST_WAITING;
  // if(result < dist_wait && result > dist_chase)
  // my.STATE = ST_WAITING;
 }
else
{
 my.STATE = ST_WAITING;
}



This way you can use one scan and not have to adjust the scan length in each and every STATE that will further reduce the STATE code blocks lines.

More reduction in the STATE can be achieved by removing to "face the player - code" from 3 out of 4 STATE's and just placing it once above the c_move(..)

Re: Flying dragon move backward [Re: ] #455229
10/14/15 08:35
10/14/15 08:35
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
yes you're correct 1 scan is better that a bunch , but also think about this , your using the return value of the scan which is simply a distance , so instead of a scan with flag evaluation routines etc , 1 vec_dist which directly states the evaluated entities should be even better .



Compulsive compiler
Re: Flying dragon move backward [Re: Wjbender] #455238
10/14/15 16:20
10/14/15 16:20

M
Malice
Unregistered
Malice
Unregistered
M



@Wjbender - Lol, Yes you are right! that's how I would have done it, but I try hack what the poster has. c_scan should be used in triggering either the scan ent's event system or the scan target's event system. That's the only thing you can not do with just a proper pointer.

-- @Ruben, you choose RealSpawns code, however using a vec or skill for a speed value will allow to use one c_move not all those. Also again you can cut down c_trace's to a single trace also. Finally with that code already using vec_dist, then as Wjbender say's, there is no need for the c_scan at all.

Page 2 of 2 1 2

Gamestudio download | chip programmers | 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