Posted: 20th Apr 2023 22:53
Everything works but the position, it positions everything in a row and not random like I ask.

So in the function when i say

random(800,1400),5,random(800,1500)

it places everything in uniform rows.

But when I position objects out of the function it places them randomly.

+ Code Snippet
function LoadItems(Texture$,Max_Number_Items,Model$,Scale_X#,Scale_Y#,Scale_Z#,X#,Y#,Z#)
	
item_Image=LoadImage(Texture$)	

for x=0 to Max_Number_Items
Model_Name=LoadObject(Model$)	
SetObjectImage( Model_Name, item_Image, 0 )
SetObjectAlphaMask(Model_Name,1) 
SetObjectScalePermanent(Model_Name,Scale_X#,Scale_Y#,Scale_Z#)
SetObjectPosition(Model_Name,X#,Y#,Z#)
SetObjectRotation( Model_Name, random(-5,5), random(1,90), random(-5,5) )
SetObjectCastShadow(Model_Name,0)
SetObjectCullMode(Model_Name,1)
next x	
	
endfunction
Posted: 21st Apr 2023 0:48
you're only setting X#,Y#, Z# once via function parameter; set them in your for/next loop.

you may want to pass MinX#/MaxX#, et al, through parameters instead and then in your for/next do something like X# = Random(MinX#,MaxX#), etc.

otherwise, there is more code that you're not showing that could be the culprit.
Posted: 21st Apr 2023 1:29
Virtual Nomad

Well that didn't work either and I check all my code and nothing is using X# Y# Z# values.

this works but this is as far as it will let me do for positions.

+ Code Snippet
function LoadItems(Texture$,Max_Number_Items,Model$,Scale_X#,Scale_Y#,Scale_Z#)
	
item_Image=LoadImage(Texture$)	

for x=0 to Max_Number_Items
Model_Name=LoadObject(Model$)	
SetObjectImage( Model_Name, item_Image, 0 )
SetObjectAlphaMask(Model_Name,1) 
SetObjectScale(Model_Name,Scale_X#,Scale_Y#,Scale_Z#)
Posx#=random(800,4000)
Posz#=random(800,4000)
posy#=GetObjectHeightMapHeight( 10,Posx#,Posz#)
SetObjectPosition(Model_Name,Posx#,posy#,Posz#)
SetObjectRotation( Model_Name, random(-5,5), random(1,90), random(-5,5) )
SetObjectCastShadow(Model_Name,0)
SetObjectScreenCulling(Model_Name,1)

next x	
	
	
endfunction
Posted: 21st Apr 2023 3:07
that's pretty much what i was suggesting but what doesn't your 2nd function do for you? (at a glance it seems fine).

meanwhile, i updated this just for you (uses a standard 3d ray since i thought i saw you using that in another recent thread).

hope it helps.

note the storage of objects in an array which you don't seem to be doing above (and the note, there).
Posted: 21st Apr 2023 3:11
Sorry, didn't see your post
Posted: 21st Apr 2023 4:00
meanwhile, i updated this just for you (uses a standard 3d ray since i thought i saw you using that in another recent thread).

Thank you, Pretty much I am loading objects in game and after collecting them they delete, but my program freezes so i am forced to hide them.

I figured out how to cast a ray down to my water and that works now.

But I will look at your code and learn from it, thank you so much.

EDIT

I can not pass XYZ into the function. Just inside the function.

Here is my code that freezes my game.

+ Code Snippet
function InventorySetUp()

x=random(100,105) 
Pickup.items=LoadObject("Items\Item_"+STR(x)+".x")	
Create3DPhysicsKinematicBody(Pickup.items)
SetObjectScale(Pickup.items,0.5,0.5,0.5)
playerang=GetObjectAngleX(Player)
SetObjectPosition(Pickup.items,getobjectx(player)+playerang+50,getobjecty(player)+5,getobjectz(player))
Pickup.ItemImage=loadimage("Items\"+STR(x)+".png")
setObjectImage(Pickup.items,Pickup.ItemImage,0)
global This2V3
This2V3= CreateVector3(getobjectx(Pickup.items),getobjecty(Pickup.items),getobjectz(Pickup.items))  
InventoryPickUps.Insertsorted(Pickup)

endfunction

function PickUpItems()

For x=InventoryPickUps.length to 0 Step -1

if GetObjectExists(InventoryPickUps[ x].Items)=1
hitID = GetObjects3DPhysicsContactPositionVector(InventoryPickUps[ x].Items,Player,This2V3)

if hitID=1
SetObjectVisible(InventoryPickUps[ x].Items,0)
SetObjectPosition(InventoryPickUps[ x].Items,0,0,0)

endif
endif

next x

endfunction
Posted: 21st Apr 2023 11:35
I don't know... but would you need to update stuff within your For / Next loop using Sync()

Or does that physics command need updating with Step3DPhysicsWorld(). Just a shot in the dark
Posted: 21st Apr 2023 12:00
what are you doing with This2V3?

meanwhile, on hiding objects vs deleting them, when you delete a bullet object, you need to delete both the object and the physics body separately (both have the same id) or you will run into issues.
Posted: 21st Apr 2023 18:12
While you're iterating through an arry ( list ) with for..next, you have to decrease your counter when deleting items in the loop, like:
+ Code Snippet
for i=1 to shot.length
	if shot[i].x > 100 or shot[i].x < 0 or shot[i].y > 100 or shot[i].y < 0		// shot outside screen?
		DeleteSprite ( shot[i].ID )                                         		// yeah, so delete the sprite
  		shot.remove(i)                                                      		// and remove the shot from the list
   		dec i                                                               		// THIS ONE IS IMPORTANT, BECAUSE WE ARE KILLING LIST ENTRIES WHILE ITERATING THROUGH THE LIST
   	endif   
next i


Also, here's a simple method to do raycasts from from 2D mouse position into a 3D world. Just click on the spheres to delete them:
+ Code Snippet
SetErrorMode			( 2 )
SetWindowSize		( 1024, 768, 0 )
SetVirtualResolution	( 1024, 768 )
SetSyncRate			( 60, 0 )
UseNewDefaultFonts	( 1 )

// CAM stuff
SetCameraRange		( 1, 1, 500 )
SetCameraPosition	( 1, 0, 0, -100 )
SetCameraLookAt		( 1, 0, 0, 0, 0 )

// create some spheres and scatter them in front of the cam
dim sphere[9] as integer
for i = 0 to 9
    sphere[i] 			= CreateObjectSphere ( 10, 10, 10 )
    SetObjectPosition	( sphere[i], random ( 0, 100 ) -50, random ( 0, 80 ) -40, random ( 0, 50 ) )
    SetObjectColor		( sphere[i], random ( 0, 255 ), random ( 0, 255 ), random ( 0, 255 ), 255 )
next i
      

do

     if GetRawMouseLeftPressed()
     	
     	mouseX = ScreenToWorldX ( GetPointerX() ) 
    	mouseY = ScreenToWorldY ( GetPointerY() )
    
    	// check for object hit
    	object_hit = ShootRay ( 0, mouseX, mouseY )
      
    	// if an object has been hit, delete it
    	if object_hit <> 0
   			if GetObjectExists ( object_hit )
     			DeleteObject ( object_hit )
      		endif
        endif	 
        
	endif
 
    Sync()
    
loop

    
function ShootRay ( objectID, mx, my )
     
    distance = 500
      
    unit_x# = Get3DVectorXFromScreen ( mx, my )	// vectors are normalized here, so we use a factor of 500 when calculating our end positions to extend our vectors into the world
    unit_y# = Get3DVectorYFromScreen ( mx, my )
    unit_z# = Get3DVectorZFromScreen ( mx, my )
     
    start_x# = GetCameraX ( 1 )
    start_y# = GetCameraY ( 1 )
    start_z# = GetCameraZ ( 1 )  
 
    end_x# = distance * unit_x# + start_x#
    end_y# = distance * unit_y# + start_y#
    end_z# = distance * unit_z# + start_z#
   
    hitID = ObjectRayCast ( objectID, start_x#, start_y#, start_z#, end_x#, end_y#, end_z# )
 
endfunction hitID


Hope that helps.

PSY
Posted: 21st Apr 2023 18:16
Hi ando

I do sync and also Step3DPhysicsWorld() already and that is a must have. But thank you anyway.

Virtual Nomad

The This2V3 is for a vector 3 to hold position info for collision.

https://www.appgamekit.com/documentation-studio/Reference/Maths/CreateVector3.htm

I thought this could be crashing my game but I tried just checking collision with a ray but it still crashed so i keeping the vector 3, it works better.

Ok i will look into that and see if it works, I did delete the physics body and object at the same time so I will let you know.

Edit

PSY

I will try your idea for deleting objects thank you, I will update you if it works.
Posted: 21st Apr 2023 18:35
Oh my lord this works and thank you so much PSY

+ Code Snippet
function PickUpItems()

For x=InventoryPickUps.length to 0 Step -1

if GetObjectExists(InventoryPickUps[ x].Items)=1
hitID = GetObjects3DPhysicsContactPositionVector(InventoryPickUps[ x].Items,Player,This2V3)

    if InventoryPickUps[ x].Items> 0 and hitID=1
        Deleteobject ( InventoryPickUps[ x].Items )                                                 // yeah, so delete the sprite
        InventoryPickUps.remove(x)                                                              // and remove the shot from the list
        dec x                                                                       // THIS ONE IS IMPORTANT, BECAUSE WE ARE KILLING LIST ENTRIES WHILE ITERATING THROUGH THE LIST
    endif  
endif

next x

endfunction
Posted: 21st Apr 2023 20:05
@Game_Code_here

You're welcome
I know the relief when you tinker with a code for hours and finally it works