Thanks Latch.
Quote: "Also, the use of spheres as waypoint markers will quickly destroy performance - especially with collision set to on and to spheres."
What would you suggest using instead? I can't use plains because the spheres actually rotate to align the path objects.
Quote: "1. Why only 5 paths?"
No reason, just picked a number. It shouldn't be a problem to increase although I wasn't thinking about using 100 paths. The only problem I see is what you mentioned about the performance hit from all those objects.
Quote: "2. How will the waypoint data be used in game?"
The .txt file that is created can be read into the game as an array. It would contain the # of paths, path #, # of waypoints in each path and XZ coord of each waypoint. Once the creature picks a path it would just move from point to point.
Quote: "3. In terms of the editor, why manage and record the rotations of the waypoints?"
In addition to the txt file used by the game, the editor creates a .dat file with the data required to recreate all the saved waypoints and path objects. The rotations are required so the waypoints and path segment object will line up properly. This data is not needed for the actual game.
Quote: "Does this seem reasonable?"
Sounds good. We will just have to consider that if the player leaves the house, the outside creatures will have to switch to pathfinding (A* or something simpler) to track and approach the player.
Quote: "In regards to shooting, I don't think it will be necessary to use the triangle math to calculate the impact point on a creature, though I still haven't tested it's speed versus the method I've come up with."
Seems like it works well. I have been trying to use triangle math as you suggested but I'm not quite there yet. Below is the code I've got so far. Basically it calculates a position X distance from the gun (bulletdist) and places a sphere at that location. It then places a long object box connecting the gun to the sphere. I used SET OBJECT COLLISION TO BOXES because I couldn't get the collision box to work (I didn't know about the rotation flag you mentioned in your last post, that may be what I was missing). Anyway, if collision is detected it uses a combination of right triangle math and the NEWXVALUE command to place the shot on the creature (a cube object in this program). It seems somewhat accurate within this well defined environment. I don't think it will work (in its current state) if the target was moved behind or to the side of the gun. I'll be glad to go with your version. One thing I was thinking about, how will either one of our methods work if the creature is at some odd angle to the gun? So, if the creature is directly facing the gun it shouldn't be too hard to relate the XYZ coord of the hit to a part of the creatures body. Might also work well if the creatures back is to the gun. But how do you place the damage if the creature is at a 48 degree angle to the gun? How do you know what body part is has hit?
I've only got to check out your static collision editor for a few minutes. Looks great! It must have taken forever to set up boxes for the whole castle. I'll get back to you with my FPS but keep in mind, my PC is old (Pentium 4). I'm getting a new one in a couple of weeks (the new Intel i7-920 chip so I can join the 21 century)
I did not fall through any areas.
remstart
==============================================================
= Title : Collision using right angles
= Author : No Time To Code
= Date : 11/20/09
= Update :
= Version:
==============================================================
Comments Test for collison point using right angle trig
==============================================================
==============================================================
Object/Image Directory
==============================================================
OBJECTS
1 Creature
2 Gun
3 Bullet
5 Bullet path
10 - 100 Bullet holes
IMAGES
SOUNDS
==============================================================
remend
remstart
from website: http://www.themathpage.com/atrig/solve-right-triangles.htm
Example 1. Given an acute angle and one side. Solve the right triangle ABC if angle A is 36°,
and side c is 10 cm.
Solution. Since angle A is 36°, then angle B is 90° - 36° = 54°.
To find an unknown side, say a, proceed as follows:
1. Make the unknown side the numerator of a fraction, and make the known side the denominator.
Unknown
Known = a
10
2. Name that function of the angle.
Unknown
Known = a
10 = sin 36°
3. Use the trigonometric Table to evaluate that function.
Unknown
Known = a
10 = sin 36° = .588
4. Solve for the unknown side.
a = 10 × .588 cm = 5.88 cm
remend
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
autocam off
set display mode 800,600,32
sync on
sync rate 0
hide mouse
`Lock CLI
rem =============================================================
rem = MAIN
rem =============================================================
_main:
gosub _init
`Define variables
camX# = 1000
camY# = 50
camZ# = 150
do
text 0,30,"Gun x angle" + Str$(gunax#)
text 0,50,"Gun y angle" + Str$(gunay#)
text 0,70,"Gun z angle" + Str$(gunaz#)
text 0,100,"Bullet x " + Str$(bx#)
text 0,120,"Bullet y " + Str$(by#)
text 0,140,"Bullet z " + Str$(bz#)
text 0,160,"step# " + Str$(step#)
text 0,180,"Hypot " + str$(hypot#)
text 0,200,"Xdist " + str$(xdist#)
`text 0,160,"Collision = :" + Str$(Collision)
`text 0,180,"Distance# : " + Str$(dist#)
`text 0,200,"Target distance: " + str$(targetdist)
text 0,220,"Creature z pos " + str$(object position z(creature))
text 0,300,"Camera x pos " + str$(camera position x() )
text 0,320,"Camera y pos " + str$(camera position y() )
text 0,340,"Camera z pos " + str$(camera position z() )
text 0,380,"Yheight = " + Str$(yheight#)
gosub _mousemove
gosub _mouselook
gosub _aimgun
rem Shoot
If spacekey() and shoot = false then gosub _shoot
If shoot then gosub _collision
If hit
gosub _place_hole
hit = false
shoot = false
wait 1000
If object exist(path) then Delete object path
If object exist(bullet) then Delete object bullet
Endif
position camera camX#,camY#,camZ#
sync
loop
_aimgun:
gunax# = object angle x(gun)
gunay# = object angle y(gun)
gunaz# = object angle z(gun)
If keystate(200) then gunax# = wrapvalue(gunax#-2)
if keystate(208) then gunax# = wrapvalue(gunax#+2)
If keystate(203) then gunay# = wrapvalue(gunay#+5)
If keystate(205) then gunay# = wrapvalue(gunay#-5)
`If gunax# > 90 then gunax#=90
`If gunax# < 270 then gunax#=0
xrotate object gun,gunax#
yrotate object gun,gunay#
Return
_shoot:
gunx# = object position x(gun)
guny# = object position y(gun)
gunz# = object position z(gun)
crex# = object position x(creature)
crey# = object position y(creature)
crez# = object position z(creature)
rem ------------------------------------------------------------------
rem | Place bullet
rem | calculate new co-ordinates based on new distance values.
rem | This code thanks to DB Forum user Rye
rem ------------------------------------------------------------------
dist#=bulletdist*cos(gunax#)
by#=newyvalue(guny#,gunax#,bulletdist)
bx#=newxvalue(gunx#,gunay#,dist#)
bz#=newzvalue(gunz#,gunay#,dist#)
Make object sphere bullet,15
Color object bullet,RGB(255,0,0)
POsition object bullet,bx#,by#,bz#
rem -----------------------End of place bullet-------------------------------
rem calculate distance between gun and creature to get length of path object segment
psize#=distance(bx#,by#,bz#,gunx#,guny#,gunz#)
rem Calculate midpoint between parent and child to get position of path object segment
midx#=(bx#+gunx#)/2
midy#=(by#+guny#)/2
midz#=(bz#+gunz#)/2
rem Make path segment between parent and child
Make object box path,psize#,2,2
Position object path,midx#,midy#,midz#
Color object path,rgb(255,0,0)
CollBox(path)
rem Align path object between bullet and gun
`Point object bullet,gunx#,guny#,gunz#
Point object bullet,Limb Position x(gun,2),Limb Position y(gun,2),Limb Position z(gun,2)
`rotate object path,0,wrapvalue(limb angle y(gun,2)+90),limb angle x(gun,2)
rotate object path,0,wrapvalue(object angle y(gun)+90),object angle x(gun)
Set object collision on path
Set object collision to boxes path
shoot = true
Return
_place_hole:
targetdist = object position z(creature)-15
dist#=targetdist*cos(gunax#)
by#=newyvalue(guny#,gunax#,targetdist)
`bx#=newxvalue(gunx#,gunay#,dist#)
bz#=newzvalue(gunz#,gunay#,dist#)
zdist# = ABS(gunz#-crez#)
yheight# = ABS(zdist# * tan(gunax#))
hypot# = sqrt((yheight#*yheight#)+(zdist#*zdist#))
dist#=hypot#*cos(gunax#)
bx#=newxvalue(gunx#,gunay#,dist#)
Make object sphere hole,10
Color object hole,RGB(255,0,0)
`POsition object hole,bx#,by#,bz#
POsition object hole,bx#,yheight#,targetdist
inc hole
Return
_collision:
Collision = object collision(path,creature)
If Collision
hit = true
Else
wait 1000
If object exist(path) then Delete object path
If object exist(bullet) then Delete object bullet
hit = false
shoot = false
Endif
Return
_mousemove:
`Get input to move mouse and camera
If Keystate(75) then camX# = CamX#-5
If Keystate(77) then camX# = CamX#+5
If Keystate(72) then camZ# = CamZ#+5
If Keystate(80) then camZ# = CamZ#-5
`raise/lower camera
if keystate(73) then inc camY#,10
if keystate(81) then dec camY#,10
return
Rem ****************MOUSE LOOK MODE******************************
_mouselook:
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = WrapValue(CameraAngleY#+MousemoveX()*0.2)
CameraAngleX# = WrapValue(CameraAngleX#+MousemoveY()*0.2)
Yrotate camera CurveAngle(CameraAngleY#,OldCamAngleY#,24)
Xrotate camera CurveAngle(CameraAngleX#,OldCamAngleX#,24)
Return
_init:
randomize timer()
gosub _environment_variables
gosub _terrain
gosub _creature
gosub _gun
`gosub _environment_objects
return
_environment_variables:
path = 5 : rem gunshot path
true = 1
false = 0
bulletdist = 500 : rem distance bullet will travel
bullet = 3 : rem Object # for bullet
hole = 10 : rem Obj # for bullet holes
Return
_terrain:
mat=1
matx#=2000
matz#=2000
tilex=15
tilez=15
make matrix mat,matx#,matz#,tilex,tilez
Rem texture matrix
`Create and pull 1 images from bitmap
Create bitmap 1,64,64
Set current bitmap 1
ink RGB(0,0,0),RGB(0,255,255)
Box 0,0,64,64
get image 1,0,0,64,64 : `Get black image for matrix
ink RGB(255,255,255),RGB(0,0,0)
Set current bitmap 0
Delete bitmap 1
Prepare matrix texture 1,1,1,1
return
_creature:
creature = 1
Make object box creature,300,200,30
Color object creature,RGB(0,255,0)
Position object creature,1000,Object size y(creature)/2,500
CollBox(creature)
Set object collision on creature
Set object collision to boxes creature
Return
_gun:
gun = 2
Make object box gun,10,10,50
Color object gun,RGB(0,255,255)
POsition object gun,1000,10,300
Make object cube 3,5
Make mesh from object 1,3
Add limb gun,1,1
Offset limb gun,1,0,object size y(gun)/2+object size y(3)/2,20
Color limb gun,1,RGB(128,128,128)
Delete object 3
Make object cube 3,5
Make mesh from object 2,3
Add limb gun,2,2
Offset limb gun,2,0,0,object size z(gun)/2+object size z(3)/2
Color limb gun,2,RGB(128,128,128)
Delete object 3
Return
`**********************************************************************************************************
`***************************************FUNCTIONS**********************************************************
`**********************************************************************************************************
rem Calculate distance between two points
Function distance(sx#,sy#,sz#,ex#,ey#,ez#)
dist#=sqrt((sx#-ex#)^2+(sy#-ey#)^2+(sz#-ez#)^2)
EndFunction dist#
rem Create Collision box
Function CollBox(ob)
obsx#= Object Size X(ob): Rem Find the object size X
obsy#= Object Size Y(ob): Rem Find the object size Y
obsz#= Object Size Z(ob): Rem Find the object size Z
Make object Collision Box ob,0-(obsx#/2),0-(obsy#/2),0-(obsz#/2),(obsx#/2),(obsy#/2),(obsz#/2),0
endfunction