D
dcamod
Guest
Well I have been going back through steering behaviors to get them memorized and I am trying to use a formula for seek that is a bug correction I saw watching a GDC conference on Context Based Steering. Anyway when I try to implement it I get this error. I believe it is because I am multiplying a 2d vector with a single number but I am not sure why it won't work. I am using PixelatedPope's revised MojoCollective vector scripts.
Here is the error.
The correction I am trying to implement is this one. Seek is called in the step event as the script sb_seek.
Here is the code that is returning the error.
I may be way off on how I am trying to implement this. My understanding of steering behaviors is not very good. I am doing this step by step to learn and creating exercises to help me understand so if I look all over the place and lost, well now you know why.
UPDATE 1
I got rid of the error by multiplying each of the vector co-ordinates separately but it does not function the way it should at all. It is actually quite funny so anyway here are the newest changes.
UPDATE 2
Well it works now but it is super strong and I am not sure why. It does not seem to me like I have done this right but here is the new update I have. I would also like to note that the topic name is now a bit inaccurate. I no longer receive a variable is malformed error. I was trying to multiply it the wrong way I assume, but I am still unclear as to why this was incorrect.
Here is the error.
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_AI:
Variable is malformed
at gml_Script_sb_seek (line 23) - _desired *= (maxSpeed/_weight);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_sb_seek (line 23)
called from - gml_Object_obj_AI_StepNormalEvent_1 (line 8) - steering = vect_add(steering,sb_seek(mouse_x,mouse_y,1))
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_AI:
Variable is malformed
at gml_Script_sb_seek (line 23) - _desired *= (maxSpeed/_weight);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_sb_seek (line 23)
called from - gml_Object_obj_AI_StepNormalEvent_1 (line 8) - steering = vect_add(steering,sb_seek(mouse_x,mouse_y,1))
The correction I am trying to implement is this one. Seek is called in the step event as the script sb_seek.
Code:
vec2 seek(vec2 target, Agent agent) {
vec2 desired = target - agent.position;
desired *= agent.maxspeed / desired.mag();
vec2 force = desired - agent.velocity;
return force * (agent.maxForce / agent.maxSpeed);
}
Here is the code that is returning the error.
I may be way off on how I am trying to implement this. My understanding of steering behaviors is not very good. I am doing this step by step to learn and creating exercises to help me understand so if I look all over the place and lost, well now you know why.
Code:
///sb_seek(x,y,_weight)
var _target = vect2(argument[0],argument[1]);
var _weight = argument[2];
var _desired = vect_subtract(_target,position);
_desired *= (maxSpeed/_weight);
var _force = vect_subtract(_desired,velocity);
return _force * (maxForce/maxSpeed);
UPDATE 1
I got rid of the error by multiplying each of the vector co-ordinates separately but it does not function the way it should at all. It is actually quite funny so anyway here are the newest changes.
Code:
var _target = vect2(argument[0],argument[1]);
var _weight = argument[2];
var _desired = vect_subtract(_target,position);
//_desired *= (maxSpeed/_weight);
var _desired_mult = maxSpeed/_weight;
_desired = vect2(_desired[0]*_desired_mult,_desired[1]*_desired_mult)
var _force = vect_subtract(_desired,velocity);
var _force_mult = (maxForce/maxSpeed)
_force = vect2(_force[0] * _force_mult,_force[1] * _force_mult);
return _force;
UPDATE 2
Well it works now but it is super strong and I am not sure why. It does not seem to me like I have done this right but here is the new update I have. I would also like to note that the topic name is now a bit inaccurate. I no longer receive a variable is malformed error. I was trying to multiply it the wrong way I assume, but I am still unclear as to why this was incorrect.
Code:
var _target = vect2(argument[0],argument[1]);
var _weight = argument[2];
var _desired = vect_subtract(_target,position);
var _desired_mult = maxSpeed/_weight;
_desired = vect_multr(_desired,_desired_mult)
var _force = vect_subtract(_desired,velocity);
var _force_mult = (maxForce/maxSpeed)
_force = vect_multr(_force,_force_mult)
return _force;
Last edited by a moderator: