Ask a Question related to Adobe Flash, Flex & Director, Design and Development.
-
philhog73 #1
Director - modelsunderay/bonesplayer problem
Hi, I am currently attempting to make an interactive 3D game with landscape and character made in 3DS Max 2010. I have been following Deans Director Tutorials and I have used the same code slightly altered because I have only one camera and the character is using bonesplayer. This all worked well until I tried to add code from the collision detect 2 tutorial and when I pressed play it would not load. From here I disabled the register for events line and it played minus the actual detection of the mountain landscape, etc. Hope this makes sense. I am a complete newbie and apologize if it doesn't. Any help would be really appreciated.
Working code before adding collision detect script:-
-- create properties for when arrow keys are pressed
-- properties will either be TRUE or FALSE values
property pLeftArrow, pRightArrow, pDownArrow, pUpArrow
property p3Dmember -- reference to 3D cast member
property pSprite -- referebce to the 3D sprite
property pCharacter -- reference to character in the 3D world
on beginSprite me
-- initiate properties and 3D world
pSprite = sprite(me.spriteNum)
p3Dmember = sprite(me.spriteNum).member
p3Dmember.resetWorld()
pSprite = sprite(me.spriteNum)
pMember = pSprite.member
pCharacter = p3Dmember.model("hero")
pCharacter.bonesPlayer.playRate = 0
-- we must define pCharacter after we use the
-- resetWorld() command otherwise this variable
-- object will be deleted
setUpCamera
end
on setUpCamera
-- create 1 new cameras
characterCam = p3Dmember.newCamera("characterCam")
-- characterCam settings
-- set up the camera's vertical viewing angle
characterCam.fieldOfView = 75
-- position the camera
characterCam.transform.position = vector(-1250,0,450)
-- set rotation of camera
characterCam.transform.rotation = vector(90,0,270)
-- set the camera of the sprite to the characterCam
pSprite.camera = p3Dmember.camera("characterCam")
-- make cameras children of the character model
pCharacter.addChild(characterCam,#preserveParent)
end
on keyDown
-- check to see which key has been pressed
-- and set the property relating to that key to TRUE
-- 123 = left arrow key
if keypressed(123) then pLeftArrow = TRUE
-- 124 = right arrow key
if keypressed(124) then pRightArrow = TRUE
-- 125 = down arrow key
if keypressed(125) then pDownArrow = TRUE
-- 126 = up arrow key
if keypressed(126) then pUpArrow = TRUE
end
on keyUp
-- when the arrow keys are released,
-- set the properties to FALSE
pLeftArrow = FALSE
pRightArrow = FALSE
pUpArrow = FALSE
pDownArrow = FALSE
pCharacter.bonesPlayer.playRate = 0
end
on exitFrame
characterMove
end
on characterMove
-- if the right arrow is pressed,
-- rotate the character 5 degrees about the z-axis
if pRightArrow then
pCharacter.rotate(0,0,-5)
end if
--if the left arrow is pressed,
-- rotate character -5 degrees about the z-axis
if pLeftArrow then
pCharacter.rotate(0,0,5)
end if
-- if the up arrow is pressed,
-- move the character 5 pixels along the y-axis
if pUpArrow then
pCharacter.bonesPlayer.playRate = 2
pCharacter.translate(15,0,0)
end if
-- if the down arrow is pressed,
-- move the character -5 pixels along the y-axis
if pDownArrow then
pCharacter.bonesPlayer.playRate = 2
pDownArrow = FALSE
pCharacter.translate(-15,0,0)
end if
end
---------------------------------------------------------------------- ---------
With added collision detect script:-
-- create properties for when arrow keys are pressed
-- properties will either be TRUE or FALSE values
property pLeftArrow, pRightArrow, pDownArrow, pUpArrow
property p3Dmember -- reference to 3D cast member
property pSprite -- reference to the 3D sprite
property pCharacter -- reference to character in the 3D world
property pCharBoundingBox -- reference to character's bounding box
on beginSprite me
-- initiate properties and 3D world
pSprite = sprite(me.spriteNum)
p3Dmember = sprite(me.spriteNum).member
p3Dmember.resetWorld()
pCharacter = p3Dmember.model("hero")
-- we must define pCharacter after we use the
-- resetWorld() command otherwise this variable
-- object will be deleted
pCharacter.bonesPlayer.playRate = 0
setUpCamera
createCharacterBoundingBox
-- register the member for regular timeMS events in order to respond to
-- user input and resolve camera collisions
-- i.e. after specified time segments activate collisionDetect handler
p3Dmember.registerForEvent(#timeMS,#collisionDetec t,me,1000,10,0)
end
on createCharacterBoundingBox
-- create model resource
charModRes = p3Dmember.newModelresource("charModRes",#box)
charModRes.height = 200
charModRes.width = 200
charModRes.length = 400
-- create model and reference to it
pCharBoundingBox = p3Dmember.newModel("CharBoundingBox",charModRes)
pCharBoundingBox.worldPosition = pCharacter.worldPosition
pCharacter.addChild(pCharBoundingBox, #preserveworld)
boxShader = p3Dmember.newShader("transparentShad",#standard)
boxShader.transparent = TRUE
-- set opacity of shader 0 is invisible - only works if transparent prop = TRUE
boxShader.blend = 50
pCharBoundingBox.shaderList = p3Dmember.shader("transparentShad")
end
on setUpCamera
-- create 1 new cameras
characterCam = p3Dmember.newCamera("characterCam")
-- characterCam settings
-- set up the camera's vertical viewing angle
characterCam.fieldOfView = 75
-- position the camera
characterCam.transform.position = vector(-1250,0,450)
-- set rotation of camera
characterCam.transform.rotation = vector(90,0,270)
-- set the camera of the sprite to the characterCam
pSprite.camera = p3Dmember.camera("characterCam")
-- make cameras children of the character model
pCharacter.addChild(characterCam,#preserveParent)
end
on collisionDetect me
-- create a list to store collision data created by modelsUnderRay
-- cast ray to left
collisionList = p3Dmember.modelsUnderRay(pCharBoundingBox.worldPos ition, \
-pCharacter.transform.yAxis,#detailed)
-- if ray picks up models, then activate checkForCollion
-- handler and send the collisionList as a parameter
if (collisionList.count) then me.checkForCollision(collisionList[1])
-- cast ray to right
collisionList = p3Dmember.modelsUnderRay(pCharBoundingBox.worldPos ition, \
pCharacter.transform.yAxis,#detailed)
-- if ray picks up models, then check for collision
if (collisionList.count) then me.checkForCollision(collisionList[1])
-- cast ray forward
collisionList = p3Dmember.modelsUnderRay(pCharBoundingBox.worldPos ition, \
pCharacter.transform.xAxis,#detailed)
-- if ray picks up models, then check for collision
if (collisionList.count) then me.checkForCollision(collisionList[1])
-- cast ray backward
collisionList = p3Dmember.modelsUnderRay(pCharBoundingBox.worldPos ition, \
-pCharacter.transform.xAxis,#detailed)
-- if ray picks up models, then check for collision
if (collisionList.count) then me.checkForCollision(collisionList[1])
end
on checkForCollision me, collisData
-- grab the #distance value from the CollisionList
dist = collisData.distance
-- check if distance is less than width of bounding box
if (dist < pCharBoundingBox.resource.width/2) then
-- get distance of penetration
diff = pCharBoundingBox.resource.width/2 - dist
-- calculate vector perpendicular to the wall's surface to move the character
-- using the #isectNormal property
tVector = collisData.isectNormal * diff
-- move the character in order to resolve the collision
pCharacter.translate(tVector,#world)
end if
end
on keyDown
-- check to see which key has been pressed
-- and set the property relating to that key to TRUE
-- 123 = left arrow key
if keypressed(123) then pLeftArrow = TRUE
-- 124 = right arrow key
if keypressed(124) then pRightArrow = TRUE
-- 125 = down arrow key
if keypressed(125) then pDownArrow = TRUE
-- 126 = up arrow key
if keypressed(126) then pUpArrow = TRUE
end
on keyUp
-- when the arrow keys are released,
-- set the properties to FALSE
pLeftArrow = FALSE
pRightArrow = FALSE
pUpArrow = FALSE
pDownArrow = FALSE
pCharacter.bonesPlayer.playRate = 0
end
on exitFrame
characterMove
end
on characterMove
-- if the right arrow is pressed,
-- rotate the character 5 degrees about the z-axis
if pRightArrow then
pCharacter.rotate(0,0,-5)
end if
--if the left arrow is pressed,
-- rotate character -5 degrees about the z-axis
if pLeftArrow then
pCharacter.rotate(0,0,5)
end if
-- if the up arrow is pressed,
-- move the character 5 pixels along the y-axis
if pUpArrow then
pCharacter.bonesPlayer.playRate = 2
pCharacter.translate(15,0,0)
end if
-- if the down arrow is pressed,
-- move the character -5 pixels along the y-axis
if pDownArrow then
pCharacter.bonesPlayer.playRate = 2
pDownArrow = FALSE
pCharacter.translate(-15,0,0)
end if
end
Junior Member
- Join Date
- Oct 2010
- Location
- uk
- Posts
- 1
-
Bonesplayer cloning
I can get a character with bones but no bonesplayer animation to use another characters bonesplayer animation --... -
Problem with director
Problem with director Hi I have a movie that I have created in my brothers computer the problem is that when i I open the .dir file I director and... -
bonesplayer.transform.position question?
I am having trouble getting the position only from a bone. It seems to suggest that it should work in the lingo help files. Is it my code? put... -
bonesplayer motion name
"ptolami" webforumsuser@macromedia.com wrote: There´s no direct way for doing this... You´d have to store the motion´s name in a variable or... -
Director in another Director navigation problem
I'm not quite sure if I follow your problem, but it sounds like you are having an issue with a linked .dcr file in author mode. Auhor mode will not...



Reply With Quote

