character home attack not working?

Blitz3D Forums/Blitz3D Beginners Area/character home attack not working?

Guy Fawkes(Posted 2010) [#1]
My player for some reason cannot tell which robot is which if there are 2 robots which are next to each other, and when within a certain distance, home attack and destroy the robot. and my player won't turn at the angle he's automatically homing attacking into he instead has the same yaw angle yet still gets automatically homed in on the object. the pickmode of the player is set to polygon (2), and obscurer is true. a1\Motion\Speed x,y,z are the speeds he is running or homing at. the pick is an attempt to make him see EXACTLY what is in front of him. the point entity points him in the direction of the robot. and the a1\homing is when he is in actual home attack mode. also, when he DOES home attack, he circles AROUND the enemy, rather than follow the enemy no matter what x,y,z the enemy is at. how can i fix this?




Ross C(Posted 2010) [#2]
*Scratches head* Can you simplify the problem your having? I couldn't really make too much sense out of the description.


Guy Fawkes(Posted 2010) [#3]
well, basically when the player home attacks, and he is within a certain distance of the enemy, he should search for ONE ENEMY ONLY the closest one that is in front of him EVEN IF there are 2 or more NEXT to that robot, then he should point AND rotate towards the enemy that was chosen, and when he comes within a certain range, blow up the enemy, bounce after destroying the enemy, bounce by 2 units, and allow for a 2nd attack if there is 2 or more robots nearby. think of it as the character finding his enemy with his site, pointing AND rotating towards him, and heat-seeking his target until his target explodes, then basically allowing for another home attack IF any other enemies are nearby, and pointing towards the closest 1.


Ross C(Posted 2010) [#4]
That's alot of code to write for that. It's not exactly a problem, more like you want someone to write a big chunk of code. Do you have any more code, or, is that all you have?


Guy Fawkes(Posted 2010) [#5]
that is all i have. i already wrote the code TO home attack. just not to target the enemy closest.


_PJ_(Posted 2010) [#6]
Add in a clause to your If statement for "Not(IsAttacking)" then Exit before the first EndIf
This should ensure that the iteration stops once the first valid candidate is found.


Guy Fawkes(Posted 2010) [#7]
thanks malice, its working now i think.....


Guy Fawkes(Posted 2010) [#8]
ok how would i figure out if my player is LOOKING AT the enemy?


_PJ_(Posted 2010) [#9]
EntityInView ?


Guy Fawkes(Posted 2010) [#10]
i mean, not if its in view, if the player is actually turned TOWARDS the enemy?


_PJ_(Posted 2010) [#11]
Then use DeltaYaw and see if the result is wider than x degrees. Where x is based on a ratio between the CameraZoom and the EntityDistance, like parallax.


Matty(Posted 2010) [#12]
Use TFormNormal to see if one entity is pointing towards another...

;robot = robot being looked at
;me = the thing doing the looking

TFormNormal entityx(robot)-entityx(me),entityy(robot)-entityy(me),entityz(robot)-entityz(me),0,me

;this works out the normalised vector (ie direction only) from 'me' to 'robot' in "me's" space.

if tformedz()>0.7 then
;robot is in the front 90degree arc of me...
endif

;tformedz()>0 means in front 180 degree arc,
;tformedz()=1 means 'dead in front'...not that useful as highly unlikley.
;tformedz()<0 means in rear 180 degree arc.


Guy Fawkes(Posted 2010) [#13]
where did u get 0.7?


Guy Fawkes(Posted 2010) [#14]
here is what i got:



is this correct for when the me model is looking straight at the robot, within a few degrees?


_PJ_(Posted 2010) [#15]
0.7 represents a ratio value, the vector angle from the player to the target in this case, is within 3 tenths of facing dead-on. This is effectively 30 Gradiens or 180/10 * 3 = 54 degrees either side of 'dead-on).

The following should show this relationship:

Graphics3D 1024,768,32,6
SetBuffer BackBuffer()

SeedRnd MilliSecs()

AmbientLight 100,100,160
Global Sun=CreateLight()

PositionEntity Sun,-20,20,40

Global Cam=CreateCamera()

Global P1=CreateCone(3)
ScaleMesh P1,1,2,1
RotateMesh P1,90,0,0
EntityColor P1,255,32,32

Global P2=CreateCone(3)
ScaleMesh P2,1,2,1
RotateMesh P2,90,0,0
EntityColor P2,32,255,32

PointEntity sun,Cam

	;Put the pointers at random locations
PositionEntity P1,Rand(-5,5),0,Rand(3,15)
PositionEntity P2,Rand(-5,5),0,Rand(3,5)

	;Red P1 Is rotated about Y Axis
TurnEntity P1,0,Rand(360),0,True
	
	;Green P2 Is facing P1
PointEntity P2,P1

While (Not (EntityInView(P1,Cam) And EntityInView(P2,Cam)))
	;Position camera so both opinters are visible
	MoveEntity Cam,0,0,-1
Wend

MoveEntity Cam,0,4,-5
PointEntity Cam,P2

While Not KeyDown(1)

	;Rotate P1 with the arrow keys <- and ->
	TurnEntity P1,0,(KeyDown(205)-KeyDown(203))*5,0,True

	UpdateWorld
	RenderWorld


	Color 255,0,0
	; Get the Normal vector between P2 and P1s' orientations
	TFormNormal EntityX(P2)-EntityX(P1),EntityY(P2)-EntityY(P1),EntityZ(P2)-EntityZ(P1),0,P1
	Text 10,20,"Vector Angle Ratio: "+Str(TFormedZ())
	
	Text 10,40,"Equivalent angleoffset: "+Str((Abs(TFormedZ()*180)))

	Flip

Wend
	FreeEntity P1
	FreeEntity P2
	FreeEntity cam
	ClearWorld
	EndGraphics



Guy Fawkes(Posted 2010) [#16]
Here's what I have:



Is this good if my player needs to see if the robot is within an acute angle of 45 and -45 degrees? in other words, "line of sight"


_PJ_(Posted 2010) [#17]
For an angle of 45 degrees either side, the ratio should be:

((180/10) * x ) = 45

I'll let you figure it out ;)


Drak(Posted 2010) [#18]
Forget all that math mumbo jumbo. There's easier ways to do this that has already been stated. Simply use the DeltaYaw() command. DeltaYaw will tell you exactly how many degrees entity A would have to be rotated to point directly at entity B. What this means is that if it returns a value of say 71 degrees, is would be out of your -45 to 45 degree arc, and not visible.

Here is an example:



Guy Fawkes(Posted 2010) [#19]
omg! thanks drak! THIS is PERFECT!