≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
Fall Damage??
Posted by:
(you are not logged in)
Enter the missing letter in: "Internati?nal"
(you are not logged in)
Text:
[quote][b]DeltaXGames[/b] wrote: I implemented this in my project by drawing 3 lines from the player to the ground and calculated how long these lines were above the land. Here's the code from my project (Sorry it's a bit sloppy, I'm not a great programmer, I write this in a way I would best understand, If you have any questions, you can send me a message on facebook www.facebook.com/deltaxgames). var __deltaTime=0; var __lastTime=0; var isFirstCount=true; function getDeltaTime() { var now=(new Date()).getTime(); if (isFirstCount) { __deltaTime=0; isFirstCount=false; } else { __deltaTime=now-__lastTime; } __lastTime=now; } ccbRegisterOnFrameEvent(getDeltaTime); var player=ccbGetSceneNodeFromName("Player scene node name"); var playerHeight=18; //the height of the player var canClimbLadder=false; var isFalling=true; var inAir=true; var airTime=0; var isFirstFall=true; function gameLoop() { //check if player is falling var playerPos3D=ccbGetSceneNodeProperty(player, "Position"); var playerBottomYPos=playerPos3D.y-playerHeight; var startPos3D = playerPos3D; if (ccbGetCollisionPointOfWorldWithLine(startPos3D.x, startPos3D.y, startPos3D.z, startPos3D.x, playerBottomYPos, startPos3D.z)||ccbGetCollisionPointOfWorldWithLine(startPos3D.x, startPos3D.y, startPos3D.z, startPos3D.x+20, playerBottomYPos, startPos3D.z)||ccbGetCollisionPointOfWorldWithLine(startPos3D.x, startPos3D.y, startPos3D.z, startPos3D.x-20, playerBottomYPos, startPos3D.z)||ccbGetCollisionPointOfWorldWithLine(startPos3D.x, startPos3D.y, startPos3D.z, startPos3D.x, playerBottomYPos, startPos3D.z+20)||ccbGetCollisionPointOfWorldWithLine(startPos3D.x, startPos3D.y, startPos3D.z, startPos3D.x, playerBottomYPos, startPos3D.z-20)) { isFalling=false; inAir=false; } else { isFalling=true; inAir=true; } //calculate AirTime if (inAir) { airTime+=__deltaTime; } else { if (airTime>0) print("Last Air Time: "+(airTime/1000)+" Seconds"); //damage player if he falls from a high place (falls for more than 800 miliseconds) if (airTime>=800) { var name=ccbGetSceneNodeProperty(player, "Name"); currentHealth=ccbGetCopperCubeVariable(""+name+".health"); ccbSetCopperCubeVariable(""+name+".health",currentHealth-(airTime/40)); } airTime=0; } } ccbRegisterOnFrameEvent(gameLoop);[/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact