Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Stopping the user from pressing the spacebar more than once at a time

karmacomposer
Registered User
Quote
2019-10-17 01:40:28

I have my character controller almost exactly as I want him (so far). However, I am having an issue with jumping. I am using the javascript jumping script and it works great, except that the user can keep pressing the spacebar which keeps jumping and gaining altitude.

How can we only allow the spacebar be pressed one time per jump?

Here are the two code fragments (put in the main scene node):

When a key is pressed do something:

key: space
Keyevent - key pressed down
Action: If a variable has value do something
If is equal to
value
0
Execute javascript:

var jumpht =10;
var player = ccbGetSceneNodeFromName("Gremlin");
ccbSetPhysicsVelocity(player, 0, jumpht, 0)
ccbSetCopperCubeVariable("isfalling", 0)

else not set


and

Every few seconds do something:

Execute a java script

var player = ccbGetSceneNodeFromName("Gremlin");
var grounded = ccbGetSceneNodeProperty(player, "Position");

if (grounded.y <= 10)
ccbSetCopperCubeVariable("isfalling", 0)


Thanks for the help.

Mike


chenhongye
Registered User
Quote
2019-10-17 05:51:05

You can shoot rays from the bottom of your feet.Then calculate the distance between the two points。


karmacomposer
Registered User
Quote
2019-10-17 14:22:37

If I could shoot rays from the bottom of my feet, i'd be a super hero or villian.

Ummmmm - please explain what you mean by shooting rays. What commands would I use? Possibly a code chunk for help?

While I appreciate the suggestion, it means little to nothing to me since I'd have no idea how to shoot rays from any part of my body (and yes, I know you are talkng about my 3rd person player character's feet).

Mike


chenhongye
Registered User
Quote
2019-10-18 02:54:33

var start=new CL3D.Vect3d(pos.x,pos.y+5,pos.z);
var end=new CL3D.Vect3d(pos.x,pos.y-100,pos.z);
for (var g = 0; g < scene.CollisionWorld.Selectors.length; ++g) {
var l = scene.CollisionWorld.Selectors[g].getCollisionPointWithLine(start,end,true,null,true);
if (l != null) {
var f = l.getDistanceFromSQ(start);
if (f < 999999999.9) {
var objName=scene.CollisionWorld.Selectors[g].Node.Name;
//...
}
}
}


Robo
Guest
Quote
2019-10-18 12:14:47

wrote:
var start=new CL3D.Vect3d(pos.x,pos.y+5,pos.z);
var end=new CL3D.Vect3d(pos.x,pos.y-100,pos.z);
for (var g = 0; g < scene.CollisionWorld.Selectors.length; ++g) {
var l = scene.CollisionWorld.Selectors[g].getCollisionPointWithLine(start,end,true,null,true);
if (l != null) {
var f = l.getDistanceFromSQ(start);
if (f < 999999999.9) {
var objName=scene.CollisionWorld.Selectors[g].Node.Name;
//...
}
}
}


damn, that is some nice code...never knew about that and I am making a game...doh.

If I didn't know about that code I would create a new variable on start and time delay from start of jump till after set time allow jumping again..whatever works..


karmacomposer
Registered User
Quote
2019-10-19 01:34:14

wrote:
var start=new CL3D.Vect3d(pos.x,pos.y+5,pos.z);
var end=new CL3D.Vect3d(pos.x,pos.y-100,pos.z);
for (var g = 0; g < scene.CollisionWorld.Selectors.length; ++g) {
var l = scene.CollisionWorld.Selectors[g].getCollisionPointWithLine(start,end,true,null,true);
if (l != null) {
var f = l.getDistanceFromSQ(start);
if (f < 999999999.9) {
var objName=scene.CollisionWorld.Selectors[g].Node.Name;
//...
}
}
}


Wow. Thank you. Any way to explain what this does and where to put it?

Thanks.

Mike


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "?nternational" (you are not logged in)


Text:

 

  

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