Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Ball sticks to left-facing wall #86848
08/20/06 23:57
08/20/06 23:57
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
This isn't a real physics engine, so it might not belong in this forum, but this is the closest I can think of regarding how it works.

Let's say for a minute that I have a ball. Not an ordinary ball - just a cylinder that's flat on top and on the bottom, but is round when you look at it from the top. It moves around in the level and can collide with other objects. When it collides, it bounces.

And it works great - on angles facing the right. For all the other angles, instead of bouncing off of the wall, the ball sticks to it! This is my code. I've tried everything humanly possible to fix it, but nothing works.

PS: I made a post earlier and got a reply saying that BOUNCE is an xyz, not a pan-tilt-roll. I've checked the manual and it is in fact an angle, not a position.

Code:
 function ball_event
{
my_motion.x *= 0.5;
my_motion.y *= 0.5;
my_motion.z *= 0.5;
if(bounce.pan < 90) && (bounce.pan > -90)
{
my_motion.x += cos(bounce.pan)*(vec_length(my_motion));
my_motion.y += sin(bounce.pan)*(vec_length(my_motion));
}
else
{
my_motion.x -= cos(bounce.pan)*(vec_length(my_motion));
my_motion.y -= sin(bounce.pan)*(vec_length(my_motion));
}
}

action ball
{
ball_object = my;
my.event = ball_event;
my.enable_block = on;
my.enable_entity = on;
var space_on;
while(1)
{
proc_late();
ball_pan1.pos_x = int(my.x) - 33;
ball_pan1.pos_y = table_panel.pos_y + (2048 - int(my.y)) - 33;
my_motion.z = 0;
my_motion.y -= 0.25 * time;
if(key_space) && (space_on == off)
{
space_on = on;
my_motion.x -= 15 * time;
}
if(!key_space)
{
space_on = off;
}
c_move(my, nullvector, my_motion, ignore_passents+activate_trigger+use_aabb);
if(my.x < 0){my.x = 0;}
if(my.x > 1024){my.x = 1024;}
if(my.y < 0){my.y = 0;}
if(my.y > 2048){my.y = 2048;}
wait(1);
}
}



Re: Ball sticks to left-facing wall [Re: MatAllum] #86849
08/22/06 20:14
08/22/06 20:14
Joined: Aug 2003
Posts: 275
Germany
kopitzki Offline
Member
kopitzki  Offline
Member

Joined: Aug 2003
Posts: 275
Germany
BOUNCE IS an xyz-vector with a maximum of x/y/z= 1, as far as I know.
You could calculate angles first
vec_to_angle(temp, bounce);
and then
if(temp.pan < 90) && (temp.pan > -90)

Re: Ball sticks to left-facing wall [Re: kopitzki] #86850
08/25/06 23:33
08/25/06 23:33
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
Why didn't I think about that? Thanks, I'll give that a try.

Re: Ball sticks to left-facing wall [Re: MatAllum] #86851
08/26/06 00:03
08/26/06 00:03
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
Okay, I tried it out and... well, thanks, it does work better on some walls. However, it's still not entirely bug-proof... it's supposed to bounce at the correct angle and mainly slide along walls. Anyone know how this code could be improved?

Code:

function ball_event
{
my_motion.x = -my_motion.x;
my_motion.y = -my_motion.y;

my_motion.x *= 0.5;
my_motion.y *= 0.5;
vec_to_angle(temp, bounce);
if(temp.pan > -1) && (temp.pan < 181)
{
my_motion.x += cos(temp.pan)*(vec_length(my_motion));
my_motion.y -= sin(temp.pan)*(vec_length(my_motion));
}
else
{
my_motion.x -= cos(temp.pan)*(vec_length(my_motion));
my_motion.y += sin(temp.pan)*(vec_length(my_motion));
}
}

action ball
{
ball_object = my;
my.event = ball_event;
my.enable_block = on;
my.enable_entity = on;
var space_on;
while(1)
{
proc_late();
ball_pan1.pos_x = int(my.x) - 32;
ball_pan1.pos_y = table_panel.pos_y + (2048 - int(my.y)) - 32;
my_motion.z = 0;
my_motion.y -= 0.25 * time;
if(key_space) && (space_on == off)
{
space_on = on;
my_motion.x -= 15 * time;
}
if(!key_space)
{
space_on = off;
}
c_move(my, nullvector, my_motion, ignore_passents+activate_trigger+use_aabb);
if(my.x < 0){my.x = 0;}
if(my.x > 1024){my.x = 1024;}
if(my.y < 0){my.y = 0;}
if(my.y > 2048){my.y = 2048;}
my_motion.x += key_cur*0.5*time;
my_motion.x -= key_cul*0.5*time;
my_motion.y += key_cuu*0.5*time;
my_motion.y -= key_cud*0.5*time;
wait(1);
}
}



Re: Ball sticks to left-facing wall [Re: MatAllum] #86852
08/27/06 22:41
08/27/06 22:41
Joined: Aug 2003
Posts: 275
Germany
kopitzki Offline
Member
kopitzki  Offline
Member

Joined: Aug 2003
Posts: 275
Germany
I haven't tested this code:

var my_motion[3];
var my_bounce[3];
var bouncing;

function ball_event
{
bouncing=1;
vec_to_angle(my_bounce, bounce);
my_bounce.tilt=0;
my_bounce.roll=0;
}

action ball
//first part of code...
//calculate speed:
my_motion.x += (key_cur-key_cul)*0.5*time;
my_motion.y += (key_cuu-key_cud)*0.5*time;
my_motion.z=0;

//include bounce set in event function(rotate speed vector if bouncing)
if(bouncing==1){vec_rotate(my_motion,my_bounce);
bouncing=0;//instant reset

c_move(my, nullvector, my_motion, ignore_passents+activate_trigger+use_aabb);
my.x=clamp(my.x,0,1024); my.y=clamp(my.y,0,2048);
wait(1);
//rest of code


Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1