ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:    
Ambiera Forum > CopperCube > Programming and Scripting
Can someone help me with this double jump script?
Author Text

xchellx
Registered User
Quote
2018-04-27 00:35:32

I have taken a script and modified it to work for double jump.
However, I have to questions/issues:
1.) How can I make a general listener to detect collision? I dont want to put a proximity action on every object as I would have to use coppercube variables for this script if I do that.
2.) Why does the jump counter not increase in this script? Right now, it should be limited to 2 jumps and never allow you to jump again. In this, it jumps forever acting like the jump counter doesn't exist and is stuck at 0.

Behavior:
https://pastebin.com/gnWzFHYu


niko
Moderator
Quote
2018-04-27 08:22:46

About your point 1: What would you want this for, for playing a sound or something? The actual collision is done in the "collision" behavior, so this is the one you could extend to do something like this.


xchellx
Registered User
Quote
2018-04-27 10:26:05

wrote:
About your point 1: What would you want this for, for playing a sound or something? The actual collision is done in the "collision" behavior, so this is the one you could extend to do something like this.

The whole point is to reset the jump counter to zero once collision is hit. The issue is, there is no way of knowing how many meshes and primitives will be in the scene so I would have to detect collision with an listener. I cannoy use coppercube variables or actions for this script as it is standalone and depends on its own local variables.
Also, you didnt help me with point 2... I would really like some help as I cannot figure out why the jump counter never increases... I rechecked the script and it SHOULD work but doesn't.


wild-master
Registered User
Quote
2018-04-30 01:40:23

Hello.

I spent the past few hours trying to improve your script by adding the ability for it to sense every physical object below it, and I fixed the counter. I didn't use external variables. It's all in one script.

Download the Behavior here:
https://pastebin.com/raw/USZFjSC...

To make it work, I added a parameter that can be edited by normal users within the window for this Behavior.

The parameter is called this:
AdjustLengthFromMiddleOfBodyToFloorToAccommodateCharactersOfDifferentHeights

The name is disgustingly long because I want you to understand what it does. When you decide the final name for this parameter, please remember to change it in both places.

The reason an adjustment path is required is because customers will each use characters of different heights! They must adjust that parameter until it reaches right below the feet of the character!

For example, if CopperCube shows your character's position as "0, 20, 0", then you must guess a number to enter for that parameter until it leads directly under his feat, so entering the number "10" will make the script assume that his feet are at "0, 10, 0" and he will be able to jump again when he touches the ground again.

Please remember that the adjustment number must be at least one increment below his feet, so if you try to measure your character until you discover that the absolute lowest point of its 3D model has a Y Position of 0.14246, then your character's position minus the chosen number for the parameter I added must cause the final spot to be slightly below that, so 0.14245 or lower.

Just put random numbers in that parameter until you're happy with how the jumps work, but don't use negative numbers because then it will think the floor is above your character!

I hope you're not mad because I added an extra parameter. That is the only way I'm aware of that can accomplish your goal.


wild-master
Registered User
Quote
2018-04-30 20:20:10

I created a better version that allows you to edit the size of the rectangle under the feet of your character that is used to detect collisions. Some characters might be tiny and some might be huge, so the ability to edit the length and width of the rectangle/square is a great feature.

Get it here:
https://pastebin.com/raw/VnKqgmU...


wild-master
Registered User
Quote
2018-05-03 03:18:27

I improved the script again.

You can now see the collision box under your character's feet so you can customize its size very easily!

You won't be able to see it in the editor, but you will be able to see it within games for Windows and Mac OS X. Even though other platforms are unable to see the collision box, the actual collision should work on ALL platforms.

I added settings for changing the X and Y and Z positions of the collision rectangle because some people have custom pivot points that are not directly on top of the feet of their characters.

While you're testing, you should do this:
1. Set the gravity to zero in the root scene node.
2. Raise your character above the ground so you can see under his feet.
3. Move a Camera directly under him so you can see easily.
4. Adjust the size of the collision rectangle and test your game with Windows or Mac OS until you're happy with how the box aligns under the feet of your character.
5. When you're happy with the alignment, uncheck the checkbox in the panel so you won't be bothered by seeing this box in your game forever.

You can also change the color of the rectangle to avoid the possibility of it being the same color as your character's shoes/feet/wheels.

Remember, if you hate the Windows and Mac platforms, only use them to adjust the alignment of the collision box, and be reassured by knowing that the box will still function for other platforms.

Get it here:
https://pastebin.com/raw/4LeWsDP...


wild-master
Registered User
Quote
2018-05-03 14:33:18

I fixed a disgusting flaw that happened during most circumstances:
The visual rectangle wasn't always aligned with the invisible rectangle that is used for the actual detection process.

The new version is here:
https://pastebin.com/raw/NKRpbYW...


wild-master
Registered User
Quote
2018-05-03 17:36:28

I noticed a flaw that could happen during some situations, so I increased the reliability of the collision detection.

The new version is here:
https://pastebin.com/raw/EYyvqma...

The collision rectangle is now a 3D shape instead of a flat 2D plane. To increase the accuracy, please place part of the box slightly higher than the feet of your character. (Don't worry, the character's own body won't count as a collision.)

Look at this picture for an example:

https://drive.google.com/file/d/...




Note for new users:
Copy and paste that script in a text editor and save it with this filename: behavior_moveObjectByKeyboardWithDoubleJump.js

Then place that file in this directory:
Documents\CopperCube\extensions


Create reply:


Posted by: (you are not logged in)


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


Text:

 

  

Forum 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


   





Software: Ambiera Light Forum. © 2008-2018 Nikolaus Gebhardt, Ambiera e.U.