Waypoints not working right..

Blitz3D Forums/Blitz3D Beginners Area/Waypoints not working right..

Guy Fawkes(Posted 2010) [#1]
For each robot that is created, I want to copy a sphere, place it at the robot's OLD X,Y,Z position BEFORE he is set to chase my player and such. For some reason THIS code KEEPS copying the entity as he moves. I ONLY want it to copy the entity ONE time where EACH robot is AT BEFORE it moves.




Guy Fawkes(Posted 2010) [#2]
for some reason, its creating a chain of waypoints at the old x,y,z. i only want one. o.o


Oiduts Studios(Posted 2010) [#3]
Last four posts...

Waypoints not working right.. By Rez
bounce not working.... By Rez
character home attack not working? By Rez
how to make enemy go FLYING on the y and z axis? By Rez


Ross C(Posted 2010) [#4]
rez, have you tried coding your own waypoint system? If not, i encourage you to do so. It will let you have it work the exact way you need it. I fear you have no grasp of how this is coded , therefore little chance of modifying it to suit your needs.


Who was John Galt?(Posted 2010) [#5]
Last four posts...

Waypoints not working right.. By Rez
bounce not working.... By Rez
character home attack not working? By Rez
how to make enemy go FLYING on the y and z axis? By Rez

Anticipating the next thread,

"How to code a waypoint system the exact way u need it?" By Rez


Zethrax(Posted 2010) [#6]
Last four posts...

Waypoints not working right.. By Rez
bounce not working.... By Rez
character home attack not working? By Rez
how to make enemy go FLYING on the y and z axis? By Rez

"Game not working! Can you make it for me?" By Rez


Ross C(Posted 2010) [#7]
Unfortunelty, rez, these are the responses from a growing number of members on this board. Most folk are losing patience with you... Not in a nasty way i don't imagine, just through frustration. It's hard to watch someone who asks for help, not try to code his own stuff, then ask for help if it doesn't work.

You will never get any better at coding if your always going to take someone else code, then simply ask for help to get it working the way you want. That's really not the point of the whole exercise.

Usually when you help someone with a problem, they learn from that, and you see them, improve. Anyway, thought i'd just drop that in again, before you get all worked up again.


Guy Fawkes(Posted 2010) [#8]
I dont see u jerks yelling at vivaigiochi. I dont even know why I bother with u jerks anymore.

He posted twice in 1 day.


Who was John Galt?(Posted 2010) [#9]
Ross has the virtue of a little more patience than me and makes a good, constructive post. If you show that you are actually trying to learn, Rez, you will find the members of this board more than helpful.


Ross C(Posted 2010) [#10]
Hmmm. Rez, did you look at his post though?

http://www.blitzbasic.com/Community/posts.php?topic=89290

He has a problem, solves it, then uploads it to the code archives. What i'm getting at, is, do you code your own stuff at all? I'm saying this to HELP you, not to have a laugh at your expense. You will NEVER get better at coding, unless you start coding your own stuff from stratch, and learn how it works.

Now, you can sit there and call people names (again), or, try coding something very simple.

For instance, i set you a challenge of coding a very small program, that will let you move a box around the screen (in 2D), using the arrow keys. Are you able to code that from scratch?


Guy Fawkes(Posted 2010) [#11]
yes i code my own stuff. where the HELL do u think i got homing attack from?

it took me weeks to figure that code out...

and yes.

i can AND did




Ross C(Posted 2010) [#12]
Good. The point i'm making here is, if you code it yourself, making additions is far far easier. You could probably get that box to follow waypoints, very easily.

First you must consider how you will store your waypoints?

Personally, i like arrays:


Dim waypoint(10,2)



Then, simple, in order of each waypoint. Point the entity (i'm talking 3d here) in the direction of the waypoint and move it, till you get within a certain distance of ther waypoint. Upon coming to that distance, move to the next waypoint.


Guy Fawkes(Posted 2010) [#13]
its not that i cant make waypoints. its that i cant get it to STOP making waypoints ><

i need it to make ONE waypoint PER robot. that is IT


Drak(Posted 2010) [#14]
REading the first post in this forum, I'm trying to understand what you want to do exactly. From what I can gather, you want to place a waypoint in space where the robot started from, have the robot follow and attack the player, then return back to that waypoint after attacking? To help at all we need to know exactly what it is you're asking.

Waypoints would probably not be created on the fly, unless it's something like above where it's just something to return to, or whatever.

This would not really be a waypoint system, but would serve the function of giving the robot something to travel to.


Guy Fawkes(Posted 2010) [#15]
yes. that is EXACTLY it. EXCEPT i want the waypoint to stay at the robot's old x,y,z WHILE chasing / attacking the player and i only want ONE of them at EACH robot that is created's x,y,z (old), i don't want it to keep copying every time the robot moves.


PowerPC603(Posted 2010) [#16]
Are you calling the function WayPoint() every game-loop?
That might be the reason your code adds a new waypoint every move the robot makes.
Because the line
AllPivs=CopyEntity(Robot_Pivot)

adds a new waypoint every time the function is called for each robot.

You should use a CreateRobot() function when you want to create a new robot and add the waypoint (a sphere in your case) inside that function.

Then there is no possibility that your code makes additional waypoints throughout the game for every move it makes.

I've created an example how I use Createxxx() functions throughout my projects:
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

Type TPlayer
	Field Entity
End Type

Type TRobot
	Field X, Y, Z
	Field Entity
	Field Waypoint
End Type

; Create one player
Global Player.TPlayer = CreatePlayer()

; Create the ground floor
Global plane = CreatePlane()

; Create a camera and point it towards the floor
Global camera = CreateCamera()
PositionEntity camera, 0, 20, -50
PointEntity camera, plane



; Main loop
While Not KeyHit(1)
	; If spacebar is hit, create a new robot at some random coordinate
	If KeyHit(57) Then
		X = Rand(-20, 20)
		Y = 0
		Z = Rand(-20, 20)
		CreateRobot(X, Y, Z)
	EndIf

	; Allow the player to move
	MovePlayer()
	; Move all robots
	MoveAllRobots()

	RenderWorld
	Flip
Wend

End



; This function creates one player instance
Function CreatePlayer.TPlayer()
	; Create a new player instance
	Local P.TPlayer = New TPlayer
	; Give the player instance a visible mesh
	P\Entity = CreateCone()
	; Make the cone a bit bigger
	ScaleEntity P\Entity, 5, 5, 5
	; Color the player mesh green
	EntityColor P\Entity, 0, 255, 0

	; Return the player instance to the calling routine
	Return P
End Function

; This function is used to create a new robot instance
Function CreateRobot.TRobot(X, Y, Z)
	; Create a new robot instance
	Local Robot.TRobot = New TRobot
	; Store the starting position for further use somewhere (if needed)
	Robot\X = X : Robot\Y = Y : Robot\Z = Z
	; Create the robot mesh
	Robot\Entity = CreateCube()
	; Create the waypoint
	Robot\Waypoint = CreateSphere()
	; Position the robot and the waypoint to the robot's starting coordinates
	PositionEntity Robot\Entity, X, Y, Z
	PositionEntity Robot\Waypoint, X, Y, Z
	; Color the meshes (robot = blue, waypoint = red)
	EntityColor Robot\Entity, 0, 0, 255
	EntityColor Robot\Waypoint, 255, 0, 0

	; Return the robot instance to the calling routine
	Return Robot
End Function

Function MovePlayer()
	If KeyDown(203) Then ; Left
		TurnEntity Player\Entity, 0, 2, 0
	EndIf
	If KeyDown(205) Then ; Right
		TurnEntity Player\Entity, 0, -2, 0
	EndIf
	If KeyDown(200) Then ; Forward
		MoveEntity Player\Entity, 0, 0, 0.2
	EndIf
	If KeyDown(208) Then ; Backward
		MoveEntity Player\Entity, 0, 0, -0.2
	EndIf
End Function

; This function let's all robot within 10.0 units of the player chase the player, and sends the robots outside this range to their waypoint
Function MoveAllRobots()
	; Process all robots
	For Robot.TRobot = Each TRobot
		; If the distance between the robot and the player is smaller than 10.0 units
		If EntityDistance(Robot\Entity, Player\Entity) < 10.0 Then
			; If the robot hasn't reached the player yet
			If EntityDistance(Robot\Entity, Player\Entity) > 0.1 Then
				; Point the robot towards the player
				PointEntity Robot\Entity, Player\Entity
				; And move towards the player
				MoveEntity Robot\Entity, 0, 0, 0.1
			EndIf
		Else
		; The robot was further away from the player than 10.0 units
			; If the robot hasn't reached his waypoint yet
			If EntityDistance(Robot\Entity, Robot\Waypoint) > 0.1 Then
				; Point the robot towards it's own waypoint (it's starting position)
				PointEntity Robot\Entity, Robot\Waypoint
				; Move the robot towards it's waypoint
				MoveEntity Robot\Entity, 0, 0, 0.1
			EndIf
		EndIf
	Next
End Function


You'll see that the CreateRobot() function creates both the robot entity and the waypoint.
When you hit the spacebar, a new robot (along with it's waypoint) is created. There is no need to check elsewhere in the program if his waypoint is already created (and create a new one if it hasn't), because you know it has been created when you created the robot.

Move the player with the arrow keys.
If a robot is within 10.0 units of the player, he will chase the player.
If the robot is not within this range (too far away from the player), he moves back to his waypoint.


Guy Fawkes(Posted 2010) [#17]
ok, i followed ur guide and came up with this.



the waypoints were created in the right places. only problem is, the robot kept moving and moving and moving on the z axis, and did not go back to the waypoint. is this function correct? if not, how can i fix it?

MoveAllRobots() also goes into the main loop


Drak(Posted 2010) [#18]
There is a super easy way to do this, and I'll explain without using actual code, as my dinner is about ready.

Give your robots a field called "status". This will simply hold a variable that will instruct the robot on what to do.

This is not real code:
Type robot
    Field mesh
    Field status
    Field return_waypoint
End Type


You can, of course edit that to suit your needs. Each game loop you'll check to see what each robot it doing ONE time.

For r.robot = Each robot
    Select r\status
       Case 1 ;this could be idle, or look for player
           ;Here you can have it look for player, check distances, whatever
           ;Then, if the robot sees the player....
           r\status = 2    ;change status to 2, which can be drop a waypoint

       Case 2  ;drop a waypoint
           ;here you'll get r\mesh's coordinates
           ;then create an actual waypoint and store it in r\return_waypoint, and place it at the r\mesh's coords
           ;after that, set it to status 3
           r\status = 3
       Case 3
           ;Case 3 can be the code to follow and attack the player
           ;after attacking or whatever it's supposed to do...
           ;set status to 4
           r\status = 4
       Case 4
           ;Case 4 can be return to waypoint
           ;so you'll point r\mesh at r\return_waypoint
           ;then move it towards the waypoint...
           ;You'll check distance of the r\mesh to r\waypoint
           ;if you're say within 1 entitydistance of the waypoint...
           ;set the status back to 1 and delete the r\return_waypoint
           r\status = 1
           delete r\return_waypoint
       End select
Next




Using status is a VERY easy way to control exactly what your entities are doing... Each robot will stay in each state until it meets the criteria to switch to a different state. Just remember to SET the status to 1 when the robot is created.


PowerPC603(Posted 2010) [#19]
@Rez: You have one "EndIf" too many just before the function ends.

I don't know how you created the Robot_Piv, so I cannot tell what's the problem.
If you use the code you've used in your first post, you created it as RobotPiv (without the underscore).

Are you using one global pivot or do you create one pivot for each robot?
In case of one pivot for every robot, do you attach it to the robot's instance (like in my CreateRobot() function)?


Guy Fawkes(Posted 2010) [#20]
I global it, and then create the pivot with each robot.




here:




wmaass(Posted 2010) [#21]
Take Drak's advice. I have a status field for almost all types that I use.


Guy Fawkes(Posted 2010) [#22]
it is the waypoint that's doing it. i think. here's my code, and im STILL having problems w/ the robot 'running away from the waypoint'



MoveAllRobots() i put above updateworld()


Guy Fawkes(Posted 2010) [#23]
i found the problem. they all think that one waypoint WAY in to the 2nd half of the level is the central waypoint so they're all going to it at the same time. how can i fix this with the code listed above?


PowerPC603(Posted 2010) [#24]
You can fix it by removing that global Robot_Piv.

I've given you the example that holds the waypoint for each robot inside the robot's instance. See the CreateRobot() function.

You've modified it so that all waypoints are linked to Robot_Piv.

What you're actually doing, is creating spheres (that represent the robot's waypoint) and store the reference into Robot_Piv every time.
Doing so overwrites the reference to the previous waypoint.

Let's assume you're creating 20 robots.

You create 20 tObject instances, each with their own reference to the robot's mesh (o\Entity), but you link the robot's waypoint to the global Robot_Piv. Why don't you use the extra field in the tObject's type instance to hold the reference to that robot's waypoint, like shown in my example?

You've in fact created 20 waypoints, but the Robot_Piv will only reference the last created waypoint, and you've de-referenced the 19 previous waypoints.
This is problem number 1: a massive memory-leak.
Because the first 19 waypoints do exist (the meshes), but you cannot interact with them anymore, as you've overwritten that reference 20 times.
If you want to delete a robot (using your code), you can only delete the robot's mesh (o\Entity) and the tObject instance that represents your robot, but there is no way you can delete it's waypoint, as you lost it by overwriting the waypoint each time. The waypoint is de-referenced and you cannot retrieve it anymore, whatever you do.

The second problem is that you only keep the reference to the last waypoint.
That way, your robots will all move to this last waypoint when they lose the player.
So you've created a programming bug.

Keep your coding simple, step by step. And build your code logically.

If every robot needs it's own waypoint, there is no need to hold that reference in a global variable that you overwrite every time.
This creates: 1) a massive memory-leak, 2) a bug with unexpected behaviour of all your robots.
If every robot needs it's own waypoint, then include a field in the robot's instance to hold a reference to it's own waypoint, like I showed you.


Guy Fawkes(Posted 2010) [#25]
thanks powerpc, that worked!


Guy Fawkes(Posted 2010) [#26]
ok the CODE works. but for some reason when u have more than 1 robot next to each other, the speed of the robot speeds up by nearly double its given amount. how can i fix it so that ALL robot speeds near/far are equal?



and for some reason the robot when he gets back to his waypoint keeps wanting to move, which makes him look like hes glitched. how can i fix both?


_PJ_(Posted 2010) [#27]
If o\ObjType = OBJTYPE_ROBOT And (p\Motion\Ground = True)
				o\Motion\Speed\Z# = .4


If EntityDistance(o\Entity, o\Robot_Piv) > 0.1 Then
				; Point the robot towards it's own waypoint (it's starting position)
						PointEntity o\Entity, o\Robot_Piv
				; Move the robot towards it's waypoint
						MoveEntity o\Entity, 0, 0, o\Motion\Speed\Z#
					EndIf


Can you spot the problem?

You might consider HOW FAST the thing is moving, and HOW LARGE the radius of detection is...


Guy Fawkes(Posted 2010) [#28]
.4 is NOT very fast.

and im not sure how big the radius is


Guy Fawkes(Posted 2010) [#29]
the radius is 2.20


Drak(Posted 2010) [#30]
.4 can actually be fast if something is moving .4 every frame. Even at 40 frames per second thats 16 "units" per second.


Guy Fawkes(Posted 2010) [#31]
well still, how can i stop the robots from acting like they're all high when they go back to their waypoints?


_PJ_(Posted 2010) [#32]
Rez...

note I specidfied 'Radius of detection'

Since you are using EntitityDistance, rather than rely on standard collisions, your detection radius is:

EntityDistance(o\Entity, o\Robot_Piv) > 0.1 Then


Now, the speed is, as you say, .4
o\Motion\Speed\Z# = .4


You claimed it isn't very fast, but I think if you stufdy the lines of code here (or rather, those I quoted earlier), the RELATIVE MAGNITUDE of the speed is quite significant.

Once again, these should be enough clues to figure out the problem.

This is YOUR program, your code (should be), so YOU OUGHT TO KNOW WHAT IT IS DOING!
Don't get defensive, I am hoping you will actually look at the code you have written, and THINK about what it is ACTUALLY DOING.
This is the only way you will understand why certain bugs appear, and how to solve them!


Guy Fawkes(Posted 2010) [#33]
the enemy basically jitters. i thought about it, and idk why he... wait. it's 0.1 isnt it? it should be = 0.0....


Guy Fawkes(Posted 2010) [#34]
should it?


_PJ_(Posted 2010) [#35]

it's 0.1 isnt it? it should be = 0.0....



Wrong.

-------------------

Currently, your robots head to their waypoints.
They are considered to be AT the waypoint when they are within 0.1 units away.

However, each update, your robots MOVE by 0.4

So if a Robot is say, 1 unit away, he moves 0.4 towards the waypoint.
This puts him at 0.6 Away, still not close enough, so he moves again...
He moves again 0.4 units, and arrives at 0.2 units from the Waypoint.
This is STILL outside the 0.1 boundary, so once more, he moves...

However, he will move THROUGH The waypoint, since he is moving 0.4 units, when he only needs to move 0.2

This puts him the other side of the waypoint ( 0.2 units away again)

Since he will never REACH the waypoint boundary of 0.1, he will continue to jump through the Waypoint between 0.2 and -0.2 units away. Giving the jittery appearance.








*Checks of <=0.0 when dealing with floats are BAD (uunless you just need to check for negatives) since tiny inaccuracies will mean you never get the result you want :) )


Guy Fawkes(Posted 2010) [#36]
so how would i stop the robot from acting like he's had 50 cups of coffee?


_PJ_(Posted 2010) [#37]
.


Guy Fawkes(Posted 2010) [#38]
?


_PJ_(Posted 2010) [#39]
Do you understand WHY the robot is 'jittering' ?


Guy Fawkes(Posted 2010) [#40]
yes, he keeps trying to move to a < 0 point.. which is driving both him AND me mad....


_PJ_(Posted 2010) [#41]
No.

He keeps trying to move to within 0.1 of a point when he moves at 0.4 each time

This way, it's impossible for him EVER to be within 0.1

IF

the robot moved at a speed less than 0.1 then he will end up within the boundary and stay there

OR

IF

the boundary was larger than 0.4 the robot would end up within it and stay there


Guy Fawkes(Posted 2010) [#42]
So ur saying this will fix it?




Guy Fawkes(Posted 2010) [#43]
also, explain to me this. why when there's more than one robot next to each other. why even though i set a constant speed for the robots, are they faster than the 1s in different parts of the level that are by themselves?


Drak(Posted 2010) [#44]
You must be changing the speed somewhere in your code if you're getting different speeds when they're set the same. You should be able to set it at startup and leave it. I see that every frame you reset o\motion\speed\z# to .4, and then again the next frame set it to .4, and then the next frame set it to .4 again, and then on the next frame you set it to .4 instead of .4. Is there any other functions you're running that also control the speed of the robots?


Drak(Posted 2010) [#45]
Another thing to de-clutter your code: Instead of calling this line of code 3 times:

If EntityDistance(o\Entity, p\Objects\Entity) ;then check it ....


Do yourself a favor and store the distance in a variable. Do this instead:
distance# = EntityDistance(o\Entity, p\Objects\Entity)


This declutters your code and makes it easier to follow.
Then just check the variable against the argument.

Edit: Get rid of all those Then statements too. Try this: ok I just noticed an error in your code gimme a few minutes to work it out

Edit2:
This code is decluttered and readable, but still won't work right for you.
That's because it has no way of telling whether the robot is trying to attack the player or go to the waypoint. First it checks to see if it's less than 70 units from the player but more than 3. If it is, it points and moves towards the player. Then right after that, it checks to see if its further than .41 away from it's waypoint. If it is, it points itself back at the waypoint then moves towards it. You need to find a way to seperate these two functions so they don't both exocute in the same frame.




Guy Fawkes(Posted 2010) [#46]
JUST 1...

But i don't think that has ANYTHING to do w/ it.


Guy Fawkes(Posted 2010) [#47]
cant i just do if entitydistance(robot(blah),p\Objects\Entity) <= 0.1 then attackplayer ?


Drak(Posted 2010) [#48]
You can do it however you want, I'm just showing you an easier, simpler, cleaner way instead of calling the same thing twice.


Guy Fawkes(Posted 2010) [#49]
im not calling the o\motion\speed twice, im initializing it, then changing it


Drak(Posted 2010) [#50]
Every frame you're resetting it to .4.


Guy Fawkes(Posted 2010) [#51]
then where do i put the .4? o.o


Drak(Posted 2010) [#52]
Edit: whoops double post.


Drak(Posted 2010) [#53]
When you create the robot.

o.tObject = new tObject
o\Motion\Speed\z# = .4


Then to move it just call this:
for o.tObject = each tObject
MoveEntity o\entity, 0,0,o\Motion\Speed\z#
next



Guy Fawkes(Posted 2010) [#54]
i should've known..... thanks drak!

now what do i do about attacking? if robot comes within 0.1 feet of player, then activate attack mode?


Guy Fawkes(Posted 2010) [#55]
also, just for future reference, how would i put a health bar above each robot's head? that is made of 2 rectangles?


Drak(Posted 2010) [#56]
Yeah that will work just fine. Although you might want to make it .4 instead of .1. That way, even if the robot ends up .41 one frame, the next he will be .01 away.

If the robot happens to accidentally pass the player in one step, say he goes from .2, moves .4, he ends up .2 away on the OTHER side of the player. There is no negative EntityDistance(). So, just to be safe, keep the number just a tad larger than your movement step.


Guy Fawkes(Posted 2010) [#57]
well apparently, w/ the # 3, he's actually quite medium speed for some reason in terms of speed. he's extremely slow now for some reason w/ .4...


Guy Fawkes(Posted 2010) [#58]
also, how can i tell it, if one waypoint is chasing my player, then make the other robots go back to their waypoints?


Drak(Posted 2010) [#59]
I told you that many posts ago. Use a status field in your Types to control each one individually.

See post #18 in this thread.


Guy Fawkes(Posted 2010) [#60]
yes, i know to use it in a type. but like how would i initialize it in moveallrobots() ?


Guy Fawkes(Posted 2010) [#61]
"drop a waypoint"? i dont understand.....




Drak(Posted 2010) [#62]
It simply means place a point, which in this case is a pivot.
Here is what you'd do:

Now, remember when you create your robots you'll have to specify that the status field MUST = 1 to start to work correctly.




Guy Fawkes(Posted 2010) [#63]
um, ok. it SORTA worked. the robots follow the player when he is close. the problem now is they won't return to their individual waypoints or waypoints AT ALL for that matter. what am i doing wrong now?



create robot:



type:



also, how can i make a robot detect if another robot is both chasing and / or attacking my player and to go back to his waypoint using this new code?


Drak(Posted 2010) [#64]
You need to change type robot to whatever type you're using for your code.
The code I posted was just there to get you started, and you'll have to change the type fields to the ones you're using.

So, you'll add a Field status and a Field return_waypoint to YOUR robot type that you're already using.

You won't actually create or need to create type r.robot. Type r.robot is actually YOUR o.tObject I think. When I say r\mesh what you should have there is o\entity. So when I say r\status, it should actually be o\status, and so on. Your code will not have any robot type in it at all. Your robot type is tObject, not robot. The code wasn't meant to be actually used in your code, just get you started. r\return_waypoint will be o\return_waypoint....


Guy Fawkes(Posted 2010) [#65]
so THATS why the waypoint wont work. testing now..


Guy Fawkes(Posted 2010) [#66]
um yea. didnt work. now not only are the robots not moving back to their respective waypoints, .1 is now EXTREMELY slow again, and it wasnt earlier.



and yes i changed all the r\'s to o\'s and put the waypoint and status in the right type


Guy Fawkes(Posted 2010) [#67]
unless, is moveallrobots() supposed to go in the loop or the robot_create()?


Guy Fawkes(Posted 2010) [#68]
didnt work by putting it in create. whats going on as stated above?


Drak(Posted 2010) [#69]
Well, we need to narrow the problem down. First, do the robots follow and pursue the player? If so, status 1,2,and 3 work. We need to figure out what happens in state 5, to be able to tell if state 4 is getting called.
Try changing the color of the robot in state 5. Add Entitycolor o\entity, 255,0,255. If it changes, then state 5 works. Your problem is then in state 4 if that works. Let me know.


Guy Fawkes(Posted 2010) [#70]
state 1,2,3 work. color did NOT work. idk about 4/5...


Guy Fawkes(Posted 2010) [#71]
he gets chased. the problem is the robots dont return to their respective waypoints after the player loses the robot.


Drak(Posted 2010) [#72]
Ah I see. We are checking in state 3 for this:

distance > 70

and

distance < 3

What this means is that if distance is > 70, nothing will happen. Try inserting this right after you get dist# in state 3:

If dist > 70
     o\status = 4
End If 


That will make the robot return to state 4 if the distance exceeds 70.


Guy Fawkes(Posted 2010) [#73]
ok. it worked. but theres another problem. the robots act like they're on coffee again. and also, it can't detect whether or not another robot is attacking or chasing player




Drak(Posted 2010) [#74]
Well, as of right now, the robot will pass from o\status 5 right to o\status 4, because you don't have any attack code. So, what that means is we're not meeting the requirements under o\status 4 to change it back to o\status 1. So, each step your o\motion\speed\z# moves the robot 3 units. We can never reach the minimum of .41 stated in status 4.

Do this:
Under case 4, you'll need to change the distance checks to a larger number.
Change BOTH of the .41 to 3.1. This should fix the jittery problem.


Ginger Tea(Posted 2010) [#75]
changing the colour of the cube to represent the state is a very good idea in the preliminary stages
also why not when a robot spawns give it a number and have that number also be left on the ground where the way point is, that way you can tell which ones arnt returning home and can work out why from there


Guy Fawkes(Posted 2010) [#76]
that's a good idea, ginger tea. drak, how would i do what ginger tea just described?


Ross C(Posted 2010) [#77]
If state = 1 then entitycolor 255,0,255
If state = 2 then entitycolor 255,0,155
If state = 3 then entitycolor 255,0,55
If state = 4 then entitycolor 255,0,5
If state = 5 then entitycolor 55,0,255


Drak(Posted 2010) [#78]
Well, as I said in post #69 in this thread, the color can be changed with the entitycolor command. Just add EntityColor o\Entity, number, number, number at the beginning of each status. Give each status a different color.

Another thing you can do for testing purposes is change the o\return_waypoint = createpivot() to o\return_waypoint = createsphere(). You can see a sphere, but not a pivot. This will be useful to you to see if the waypoint is actually getting placed.

Oh, and I forgot something in case 4. You'll need to free the waypoint when the robot reaches it, otherwise there will be a memory leak there.

For further information see my *short* tutorial on this here:
http://www.blitzbasic.com/Community/posts.php?topic=89386

It shows you how to control different enemies with the status field. It also changes the colors of the enemies to identify the state they are in. Reading the code and understanding why things happen will be beneficial.


Guy Fawkes(Posted 2010) [#79]
ok. so i tried the color thing. it DOES work. he turns red in state 1, green in state 2, blue in state 3, and yellow in state 4. he's supposed to turn purple in state 5, but either that doesn't work, or i need to make the robot attack the player.

now, how can i make it so if 1 robot sees another robot chasing/attacking the player, then the other robots go back to their waypoints?


Drak(Posted 2010) [#80]
You need to attack the player. State 5 is only 1 frame, so you probably will Not see him turn purple.


Guy Fawkes(Posted 2010) [#81]
so, how can i make it so the robot can see if another robot is attacking and/or chasing the player and point him back to his waypoint?

i added Field id to the robot, and assigned the robot a random # from 1 to 10, but i don't know how to obtain that number, and use it to tell whether or not there is a robot attacking the player.


Drak(Posted 2010) [#82]
Before you try to implement this next step, is everything working correctly so far? As in the robots follow, chase, attack, return, and then go back to idle? This is paramount that this works NOW before you try to add more choices.


Guy Fawkes(Posted 2010) [#83]
yes, all 5 states are working i believe. when he's at his waypoint, he's red. when he's chased, he goes from green to blue. and when the player gets hit, he turns purple.


Guy Fawkes(Posted 2010) [#84]
so. now. how can i make it so if a robot sees the player being attacked/chased, he'll go back to his waypoint? also, how can i stop the robot from moving once he's close enough to the player?


Drak(Posted 2010) [#85]
You're not comprehending the logic of the o\status field.

Each program loop, the program cycles through each enemy ONE time. It then chooses how to control that particular enemy ONE time each loop depending on what o\status is SET to.


how can i stop the robot from moving once he's close enough to the player?




The robot will continue to follow the player so long as it is set to o\status 3. So, to get it to quit following the player, you must change o\status to something other than 3. When the robot gets to < 3 distance from the player he should switch to o\status 5, which causes him to switch to o\status 4. and so on.. and so on...

I'm going to work.


Guy Fawkes(Posted 2010) [#86]
how can i make all OTHER robots go back to their waypoints if they see one attacking / chasing the player?

that's all i need to know.


Guy Fawkes(Posted 2010) [#87]
how would this be possible?


Yeshu777(Posted 2010) [#88]
Have a reset status, whereby on one robot attacking would set all others to "return home".


Guy Fawkes(Posted 2010) [#89]
um, i already implemented a "status" for robots. I just don't know what to do to tell all others to "go home" if u know what i mean


Drak(Posted 2010) [#90]
What he means is that for the first robot that enters o\status = 3 and is chasing the player, in that chunk of code, check all other robots, and if their o\status is 3, change it to 4, which is return to waypoint.

Here is an example of how this would work:

Check robot 1, robot 1 is in state 1 and 80 units away, so he stays in o\status 1.

Check robot 2, robot 2 is in state 1 and is 69 units away from the player.
This robot does nothing this frame but change it's o\status to 2.

Next Frame:

robot 1 is now 74 units away from the player, so he is still staying in state 1.

robot 2 this frame writes down his XYZ coords and places a waypoint where he's standing. Upon placing the waypoint, his o\status is set to 3.

Next Frame:

robot 1 is now 68 units away from the player, so he does nothing more this frame then switch his status to o\status = 2.

robot 2 now is in state 3 so he first gets the distance to the player. Upon realizing he is 60 units from the player, he then points himself at the player, and moves 1 o\tObject\speed\z# towards the player.

Now here's where he tells his buddies to go back to their waypoints. He is the FIRST robot this frame to enter o\status 3, so he tells every OTHER robot in state 3 to enter state 4, which 4 is return home. How?

First you must store the robot ID# in a variable:
this_robot = o\Entity.

Then loop through all the o\tObjects
For o.tObject = Each o\tObject
if o\entity <> this_robot
if o\status = 3 then o\status = 4
end if
next

That will change all other bots in pursuit back to state 4.


Guy Fawkes(Posted 2010) [#91]
here's what i have, i did as u said, but it's not working, and if i put 2 of the same for o.tObject = each tObject, it crashes.



type:



and in robot_create:



i also have 11 robots, not 2. a few of which are by each other. i need to be able to do this for ALL robots within the range given


Yeshu777(Posted 2010) [#92]
Surely when one robot is flagged as attacking, you will have to iterate through all the other robots setting their status to return home.

As Drak said...

For o.tObject = Each o\tObject
if o\entity <> this_robot
if o\status = 3 then o\status = 4
end if
next


Drak(Posted 2010) [#93]
No you didn't do as I suggested. Go back and re-read my last post.

You're not storing the robot ID# in a variable. The robot ID# is NOT o\id. It's a reference to the entity that blitz uses. That number has to be stored in a variable to use it. I suggested you store it in a variable named this_entity.

The second time you loop through your tObjects, you must check to see if the new entity you're checking (o\entity) is not the old entity (this_entity).

Change the second loop to read:
For this.tObject = each tObject as well.

Note: This loops through ALL robots. It doesn't matter if you have 1 or 18 billion robots, or 11. The code won't differ.


Guy Fawkes(Posted 2010) [#94]
EDIT: Didn't see that last post. testing.


Drak(Posted 2010) [#95]
Here do this:
This shows the ID number blitz uses for reference:

Graphics3D 800,600
a = CreateCube()
Print a


This is the number you must store in a variable


Drak(Posted 2010) [#96]
I understand that it's looped, Rez. You can loop through all the robots WHILE looping through all your robots, effectively looping through them twice in the same frame.

Lets get this figured out in the next couple of posts, eh? Keep it under 100 posts...


Guy Fawkes(Posted 2010) [#97]
right, idc how many posts it takes, but i'll try. im taking this step-by-step.

ok, so, here's what i have so far:

robot_create:



type:



moveallrobots():



moveallrobots() is called in object robot update like this:

moveallrobots(3,70) ;min, max dist


Drak(Posted 2010) [#98]
Ok, you're very close it looks like. You're doing it right by looking at it, but you're still not storing the originating mesh into a variable.

Add this line right before for this.tobject = each tobject

this_robot = o\entity


Guy Fawkes(Posted 2010) [#99]
ok, tried it. it's still not working..



robot_create:




Drak(Posted 2010) [#100]
What isn't working? Gotta be more specific.


Yeshu777(Posted 2010) [#101]
Had a quick glance at it but shouldn't it be...


For this.tObject = Each tObject
    If this\entity <> this_robot Then
        If this\status = 3 Then this\status = 4
    End If
Next



As far as I can tell your iterating the type list using "this" then making a comparison using "o"


Drak(Posted 2010) [#102]
Yes that would be correct I believe.


Guy Fawkes(Posted 2010) [#103]
so what, do i put this\status above the if statement or what?


Drak(Posted 2010) [#104]
No.

Under case 3 you have the following:
this_robot = o\entity 
	For this.tObject = Each tObject
		If o\entity <> this_robot
			If o\status = 3 Then o\status = 4
		End If
	Next



Just for this tiny, tiny chunk of code, you need to change o\entity to this\entity and the o\status to this\status

Like this:
this_robot = o\entity 
	For this.tObject = Each tObject
		If this\entity <> this_robot
				If this\status = 3 Then this\status = 4
		End If
	Next



Guy Fawkes(Posted 2010) [#105]
THANK U! this fixed it. i think. if there's anymore problems i will let u know! THANKS drak! :)


Guy Fawkes(Posted 2010) [#106]
there IS still ONE small problem. the speed of the robotS chasing u varies when there's alot of robots around. even though I set o\Motion\Speed\Y# to .4, some robots are still faster than others. and i set it in robot_create() not in the moveallrobots() function. how can i fix this?


Drak(Posted 2010) [#107]
Rez there's one more thing you need to do. You probably won't notice it either way but you need to delete the waypoint when the robot reaches it.

Otherwise, you'll have a huge memory leak because you won't be able to access the old waypoint when a new one is created. Anyway you need to do this here:

This is under status 4
Else If dist# < o\Motion\Speed\Z#+.1
	o\status = 1	;r\status 1 can be look for player
End If


You must free the pivot we're using for the waypoint here.
Change it to this:

Else If dist# < o\Motion\Speed\Z#+.1
	o\status = 1	;r\status 1 can be look for player
        FreeEntity o\return_waypoint
End If


Edit: This may have something to do with the varying speed, as some robots were probably creating pivots over and over when they were told to cancel their pursuit every other frame.


LineOf7s(Posted 2010) [#108]
if there's anymore problems i will let u know!


I'll bet.


Yeshu777(Posted 2010) [#109]
@Res...

Don't bother thanking me, its ok...


Guy Fawkes(Posted 2010) [#110]
thanks, yeshu. sorry. i spaced. ive been up since 5 am. im literally going to sleep now.


Yeshu777(Posted 2010) [#111]
Yeah, know the feeling, same here.

No rest for a programmer.


Guy Fawkes(Posted 2010) [#112]
ditto to that bro....


Who was John Galt?(Posted 2010) [#113]
No rest for a programmer.
LOL... what would Rez know about that? He's just a requirements manager.


Ross C(Posted 2010) [#114]
.


Guy Fawkes(Posted 2010) [#115]
the same way u dont know anything, jerk. now leave me alone john! just because i ask questions DOESNT GIVE U THE RIGHT TO MESS W/ ME! And idc WHAT u have to say!


Who was John Galt?(Posted 2010) [#116]
...then don't respond to me.

It's not because you ask questions.. it's because you are lazy and expect people to write the entire thing for you, which you have achieved very well.

[Edit]In case of any misunderstanding, none of this is directed at Ross C.


_PJ_(Posted 2010) [#117]
We all ened to ask for help from time to time, and sometimes, the questions we ask, even when solved lead to further problems.
What frustrates em, though, is that the underlying understanding of how the code works isn't sinking in.

I've sugegsterd ebfore a few times, that Rez should work on something simple and straightforward first, so that he can gert to grips with the language better.
Typically, though, this has been ignored.
Ambitious projects will always lead to problems when one tries to attempt something beyond their capacity and therefore, even the help is over their head.

Looking back through the vast number of recent "help" threads started by Rez I notice a familiar pattern:

1) Question asked
2) Advice given
3) Response indicates not fully understanding (whether this is due to the advice or base level of understanding is unspecific)
4) Advice re-presented as code sample fix.
5) Response of "Thanks" when it works.
6) New problem arises.

The points show that just having working code isn't enough, Rez, unless you can truly understand WHY the code works. This also implies that on receiving the working solution, you can then understand WHY the code DIDNT work before.

Only when you can honsestly say "Yes, I Understand why" to the statements above,will you be learning and opreventing continuous problems at every step of your program.


stayne(Posted 2010) [#118]
Well put Malice.


Ross C(Posted 2010) [#119]
That's good adivce, but been given many times. Your talking to a brick wall. Just let him continue the way he's going. He's not going to change his ways, so you might as well let it be.


_PJ_(Posted 2010) [#120]
That's good adivce, but been given many times. Your talking to a brick wall. Just let him continue the way he's going. He's not going to change his ways, so you might as well let it be.


I know, Ross. I've seen you and many others really trying too, this is something of a last resort from me...


Who was John Galt?(Posted 2010) [#121]
Bottom line, he won't change because he doesn't need to. There are too many good samaritans here that are more than happy to code the entire thing for him, in spite of the fact that he is rude and shows no interest whatsoever in what the code is doing. I really do think he's a wind-up merchant.