Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name: Password:
Ambiera Forum > CopperCube > Programming and Scripting
Problems with dash ability
Author Text

dekon_17
Registered User
Quote
2022-03-16 08:35:59

Hey everyone, it's me again (sadly). I kinda finished my "Dash" ability for... Well, let's call it as "main project". The only problem left for now is that I can't figure out what causes the wrong target positioning. As you can see here, the camera is wobbling when it is mid-air (I wasn't rotating the camera using mouse while it did dash):
🔎︎

I tried to do different things, mostly with target Y position. And yet, I can't really fix this issue. Here's the code itself:
/*
<action jsname = "action_Dash" description = "Dash mechanic for BSG">

<property name = "Plr" type = "scenenode"/>
<property name = "JumpPower" type = "int"/>
<property name = "DashSpeed" type = "Int"/>

</action>
*/

action_Dash = function()
{
}

action_Dash.prototype.execute = function()
{
this.t0 = (new Date()).getTime();
this.h0 = ccbGetSceneNodeProperty(this.Plr, "Position");
var Rotation = ccbGetSceneNodeProperty(this.Plr, "Rotation");

this.DistX = Math.sin(Rotation.y * (Math.PI / 180));
this.DistZ = Math.cos(Rotation.y * (Math.PI / 180));

var me = this;
this.RegisteredFunction = function() { me.Dash(); };
ccbRegisterOnFrameEvent(this.RegisteredFunction);
}

action_Dash.prototype.Dash = function()
{
var t1 = (new Date()).getTime();
var t = (t1 - this.t0) / 1000;

var OnGround = ccbGetCopperCubeVariable ("OnGround");

var Pos = ccbGetSceneNodeProperty(this.Plr, "Position");
Pos.x += this.DistX * this.DashSpeed;
Pos.y = this.h0.y + this.JumpPower * t - (900 * t * t) / 2;
Pos.z += this.DistZ * this.DashSpeed;
ccbSetSceneNodeProperty(this.Plr, "Position", Pos);

//Problem is probably somewhere here
var Rotation = ccbGetSceneNodeProperty(this.Plr, "Rotation");
var Target = ccbGetSceneNodeProperty(this.Plr, "Target");
Target.x += Math.sin(Rotation.y * (Math.PI / 180)) * this.DashSpeed;
Target.y += Pos.y - 17.5;
Target.z += Math.cos(Rotation.y * (Math.PI / 180)) * this.DashSpeed;
ccbSetSceneNodeProperty(this.Plr, "Target", Target);
//The next part is collisions, which works fine

var ColAbs = ccbGetCollisionPointOfWorldWithLine (Pos.x, Pos.y, Pos.z, Pos.x, Pos.y - 20, Pos.z);
var ColAbsX = ccbGetCollisionPointOfWorldWithLine (Pos.x, Pos.y, Pos.z, Pos.x + this.DistX * this.DashSpeed, Pos.y, Pos.z);
var ColAbsZ = ccbGetCollisionPointOfWorldWithLine (Pos.x, Pos.y, Pos.z, Pos.x, Pos.y, Pos.z + this.DistZ * this.DashSpeed);

if (ColAbs)
var Col = ColAbs.y - Pos.y;

if ((Col >= -17.5 && OnGround == 0) || ColAbsX || ColAbsZ)
{
ccbUnregisterOnFrameEvent(this.RegisteredFunction);
ccbSetCopperCubeVariable ("OnGround", 1);
};

if (Col << -17.5)
{
ccbSetCopperCubeVariable ("OnGround", 0);
};

print (Target + " " + Pos);
};

Basicly, when player does epic dash across the whole room, the camera acts... Weird. But the reposition of camera works as intended. The target repositioning, however, is not. It goes up and down and I don't know why.

Do anyone understand what is wrong...?


sven
Registered User
Quote
2022-03-16 19:23:08

Because your player does parabolic movement that means camera target needs to be updated.

I am not exactly sure what dash means but for me player did jump.
(script can be easily change to be move fast forward without jump also if jump was not intended)

I edited script and renamed it..
its action_sDash.js so if you open my project then you find it in your scripts folder.

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



Because i had no idea what to input here:
<property name = "JumpPower" type = "int"/>
<property name = "DashSpeed" type = "Int"/>
(next time you should use default values so person who helps you doesnt have to figure those inputs out.)
(Also i dont know about your camera parameters as player (does it have collision shaper and what size and so on..)
(so i recreated collision check under camera and infrontof camera with collidewhenmove)

If i misunderstood your question then feel free to be more specific and i will help you out.


dekon_17
Registered User
Quote
2022-03-17 17:38:12

By "dash" I actually meant some sort of "super jump" in forward direction (probably like in Black Mesa). The direction shouldn't be changed by looking from side to side, so that the jump goes in locked direction only. And, actually, I have a target update that I "quoted" using bold text.

So, the character should move in one direction without any way to change its direction (kinda) while the camera is free to look around. Sadly, the target position is being changet in wrong way or something.

Also, some things about a numbers:

17.5 is a standart camera position (from ground, which is on 0);

900 is some sort of "gravity" (character weight multiplied by 10, which is gravity).

Don't know if I actually explained this well, but at least that's something...


sven
Registered User
Quote
2022-03-17 18:39:33

Now player can jump and look around while jump without changeing its jump-direction.


I edited script to fit for my needs-so you may need to edit it back.

script name is action_rDash you find it in your scripts folder if you run my example.

Download example here:
https://drive.google.com/file/d/...


dekon_17
Registered User
Quote
2022-03-17 19:26:08

Woah... That's perfect! Just as I wanted it to be!

Thanks a lot, sven! I'll try to figure out what did I done wrong with my one.


dekon_17
Registered User
Quote
2022-03-18 11:52:54

Hey, I tried to look both in your and mine codes and...

Well, I found that you've tried to make h0 variable to be recieved every frame, which, I might be wrong, is kinda... Not like it should be that way. I mean, to create this I used the next formula:
🔎︎

Where the h0 is a stating position, so, it probably shouldn't be changed (but still, I might be wrong).
Also, I SOMEHOW managed to find... A bit different way to avoid that. I made this:
var Pos = ccbGetSceneNodeProperty(this.Plr, "Position");
var OldPos = ccbGetSceneNodeProperty(this.Plr, "Position");

After that, the position calculates, and then:
var Target = ccbGetSceneNodeProperty(this.Plr, "Target");
Target.x += Pos.x - OldPos.x;
Target.y += Pos.y - OldPos.y;
Target.z += Pos.z - OldPos.z;

I still don't really understand why using formulas the result wasn't what it supposed to be. That's just weird.

Anyway, I still appreciate you for your help and patience, sven.


sven
Registered User
Quote
2022-03-18 12:01:04

Final code that i had was:

( i removed h0 )

/*
<action jsname = "action_rDash" description = "R--Dash mechanic for BSG">
<property name = "Plr" type = "scenenode"/>
<property name = "JumpPower" type = "int" default="150"/>
<property name = "DashSpeed" type = "Int" default="12"/>
</action>
*/

action_rDash = function()
{
}

action_rDash.prototype.execute = function()
{

if(ccbGetCopperCubeVariable("OnGround")==0)
{
return 0;//exit because player not on floor so probably function already running.
}

this.t0 = (new Date()).getTime();

var Rotation = ccbGetSceneNodeProperty(this.Plr, "Rotation");

this.DistX = Math.sin(Rotation.y * (Math.PI / 180));
this.DistZ = Math.cos(Rotation.y * (Math.PI / 180));

var me = this;
this.RegisteredFunction = function() { me.Dash(); };
ccbRegisterOnFrameEvent(this.RegisteredFunction);
}

action_rDash.prototype.Dash = function()
{

var t1 = (new Date()).getTime();
var t = (t1 - this.t0) / 1000;

var Pos = ccbGetSceneNodeProperty(this.Plr, "Position");
Pos.x += this.DistX * this.DashSpeed;
Pos.y += this.JumpPower * t - (900 * t * t) / 2;
Pos.z += this.DistZ * this.DashSpeed;
ccbSetSceneNodeProperty(this.Plr, "Position", Pos);

var Target = ccbGetSceneNodeProperty(this.Plr, "Target");
Target.x += this.DistX * this.DashSpeed;
Target.y += this.JumpPower * t - (900 * t * t) / 2;
Target.z += this.DistZ * this.DashSpeed;
ccbSetSceneNodeProperty(this.Plr, "Target", Target);

//HERE ADD YOUR OWN COLLISION: I TESTED WITH TOP-DOWN ONLY.
var ColDown = ccbGetCollisionPointOfWorldWithLine (Pos.x, Pos.y+120, Pos.z, Pos.x, Pos.y-10, Pos.z);
if (ColDown !=null)
{
Pos.y=ColDown.y+17.5;//set player 17.5 units up from ground(collisionpoint)
print("Landed: GroundY="+ColDown.y +" PlayerY="+Pos.y);
ccbSetSceneNodeProperty(this.Plr, "Position", Pos);//set it.
ccbSetCopperCubeVariable ("OnGround", 1);
ccbUnregisterOnFrameEvent(this.RegisteredFunction);
}else{
print("Player jump active..");
ccbSetCopperCubeVariable ("OnGround", 0);
}


}


What i did is make camera move with target.. so target wont move separate with camera, i didnt follow any formulas.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Interna?ional" (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© 2020 Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact