@IronManhood
Thanks very much for the suggestion. That seems to work really well for adding parts and creating the players how I like it.
// Project: Universal 1st/3rd person framework.
// Created: 2017-09-17
#option_explicit
#constant version#=5.5
Global playerheight#= 1.8
Global playerwidth# = 1
// Setup screen..
WindowAndDisplaySetup()
remstart
// types
Type CharacterType
Name as string // character's name
characterSpecies as integer // 1=player, 2=enemy, 3=extra, 4=monster
// physical..
Mesh as integer // body connected to this character
Height as float // mesh height
Width as float // mesh width
Weight as float // for use with physics
// coords..
x as float
y as float
z as float
// angles..
anglex as float
angley as float
anglez as float
// management..
lifetime as float
energy as float
hits as integer
EndType
Global GameCharacter as CharacterType[5] // create global array GameCharacter to hold 6 GameCharacters.
Global rightarm as integer[5]
Global gun as integer[5]
CreatePlayer(1) // create player at index #1 .
remend
////////////////////////////
type MeshIDs
body_mID as integer
rightArm_mID as integer
gun_mID as integer
leftArm_mID as integer
endtype
type Character
// vars
name as string
health as integer
mesh as MeshIDs
endtype
global players as Character[5] // create array of 5 players as type Character
function createPlayer( plr ref as Character, n$, hlt )
plr.name = n$
plr.health = hlt
addMeshesToPlayer( plr )
endfunction
function addMeshesToPlayer( plr ref as Character )
plr.mesh.body_mID = CreateObjectCapsule(playerwidth#,playerheight#,1)
SetObjectPosition(plr.mesh.body_mID, -5,0,0)
// add right arm..
plr.mesh.rightArm_mID = CreateObjectSphere(.6,10,10) //diameter, rows, columns )
SetObjectColor( plr.mesh.rightArm_mID,150,150,255,255)
SetObjectPosition(plr.mesh.rightArm_mID,0,0,0) : SetObjectRotation(plr.mesh.rightArm_mID,0,0,0) // ensure is at correct starting point.
SetObjectPosition(plr.mesh.rightArm_mID,.4,0,.1)
SetObjectRotation(plr.mesh.rightArm_mID,0,0,0)
FixObjectToObject(plr.mesh.rightArm_mID,plr.mesh.body_mID )
SetObjectCollisionMode(plr.mesh.rightArm_mID,0) //prevent self hiting
SetObjectCastShadow(plr.mesh.rightArm_mID,1)
// add gun..
plr.mesh.gun_mID = CreateObjectCylinder(1.1,.2,10) //height, diameter, segments )
SetObjectPosition(plr.mesh.gun_mID,0,0,0) : SetObjectRotation(plr.mesh.gun_mID,0,0,0) // ensure is
SetObjectPosition(plr.mesh.gun_mID,0,0,0) : SetObjectRotation(plr.mesh.gun_mID,0,0,0) // ensure is at correct starting point.
SetObjectRotation(plr.mesh.gun_mID,90,7,0) // rotate the cylinder from vertical to horizontal position(infliuences also the coords syst; x=y
SetObjectPosition(plr.mesh.gun_mID,0.2,0.15,0.4)
FixObjectToObject(plr.mesh.gun_mID,plr.mesh.rightArm_mID)
SetObjectColor(plr.mesh.gun_mID,0,0,0,255) //
SetObjectCollisionMode(plr.mesh.gun_mID,0) //prevent self hiting
SetObjectCastShadow(plr.mesh.gun_mID,1)
// add left arm..
plr.mesh.leftArm_mID = CreateObjectSphere(.6,10,10) //diameter, rows, columns )
SetObjectScale(plr.mesh.leftArm_mID,.7,1.4,1)
SetObjectColor( plr.mesh.leftArm_mID,150,150,255,255)
SetObjectPosition(plr.mesh.leftArm_mID,0,0,0) : SetObjectRotation(plr.mesh.leftArm_mID,0,0,0) // ensure is at correct starting point.
SetObjectPosition(plr.mesh.leftArm_mID,-.4,-.1,.1)
SetObjectRotation(plr.mesh.leftArm_mID,0,0,00)
FixObjectToObject(plr.mesh.leftArm_mID, plr.mesh.body_mID)
SetObjectCollisionMode(plr.mesh.leftArm_mID,0) //prevent self hiting
SetObjectCastShadow(plr.mesh.leftArm_mID,1)
endfunction
createPlayer( players[4], "Player1", 0.0 )
////////////////////////////
//SetObjectPosition( plr.mesh.body_mID , -5.0,0.0,0.0) // ??
//SetObjectPosition( plr.mesh.body_mID, -5,0,0,0) //??
// main loop..
do
//UpdatePlayer()
If GetRawKeyPressed(27) then Exit // Esc = exit(windows only)
sync()
loop
End // exit game..
Function WindowAndDisplaySetup()
// ------------not really needed for this example -------
// set window properties
SetWindowTitle("Test V"+str(version#,1) )
// set display properties
SetWindowSize(1920,1080,0)
SetWindowAllowResize(1) // allow the user to resize the window
SetVirtualResolution(1920,1080) // doesn't have to match the window
//setvirtualresolution(1024,600)
SetOrientationAllowed(1,1,1,1) // allow both portrait and landscape on mobile devices
SetSyncRate(30,0) // 30fps instead of 60 to save battery
SetScissor(0,0,0,0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1) // since version 2.0.22 we can use nicer default fonts
SetPrintSize( 20 )
SetPrintColor( 00, 00, 00,255 )
SetClearColor(1,128,198)
SetGlobal3DDepth(10000) // Sets the position of all 3D objects relative to 2D objects.
SetResolutionMode(1)
SetAntialiasMode(1)
SetImmersiveMode(1)
SetRawMouseVisible(0)
SetCameraRange(1,1,1000)
SetAmbientColor(128,128,128)
SetGenerateMipmaps(1)
// -----------------------------------------------------------
Global fog=1
// add some atmospheric fog
SetFogMode( fog )
SetFogColor( 161,183,209 )
SetFogRange( 50, 700 )
SetFogSunColor( 255,230,179 )
// -----------------------------------------------------------
SetShadowMappingMode(3)
SetShadowSmoothing(1) // random sampling
SetShadowMapSize(2048,2024)
EndFunction
Function CreateWorld()
// create a plane for things to stand on, turn its collision off, rotate it and position it under the middle box to act as a ground
// this is purely coismetic
Global planeID
planeID=CreateObjectPlane(40000,40000)
SetObjectCollisionMode(planeID,0) // this is to stop it interfering with the collision with the map
// ensure everything is at correct starting point an orientation at creation.
SetObjectPosition(planeID,0,0,0) : SetObjectRotation(planeID,0,0,0)
// put where we want it..
SetObjectRotation(planeID,90,0,0) // put it flat
SetObjectPosition(planeID,0,0,0) //realign with origin
SetObjectColor(planeID,50,200,100,255) // color it lawn style
EndFunction
However I have one question using this:
When outside of the function createPlayer() , what is the correct way to reference the meshes (or bodyparts )of the individual players in commands such as:
SetObjectPosition(ObjID, x, y, z)
or
SetObjectColor(ObjID, 200,50,50,255) ?