to stop conserving momentum after every reload. By this I mean, If the ball charges into the body which causes reload, the momentum it has when I charged into the wall is conserved and so reloads bouncing about the joint at high speed. I want it to reload with a set momentum. I have tried the following:
setVelocity
setVelocityLimit
setDynamic //(causes errors)
//plus about 5 more
So I ask, how do I get the ball to reload with a set velocity, and how do I achieve this within the collision method? Think of it like a breakwater
If you had a class for each object you wouldn’t be asking most of these questions (probably) as it would make sense how and where to put code to accomplish what that piece needs.
You need:
A slingshot class
A ball class
A class that tracks score, lives left, etc stats etc
A basket class
I’d subclass nothing and make your sprites etc members variables
by class do you mean a cpp and a header(this is how they are referred to in the default files)? Or a class that functions like a “function”. My old console example:
void AreaCalcFunc()
{
string Jole;
double x;
double h;
double u;
double a;
double b;
double H;
cout<<"Welcome to the area finder, what shape would you like to find the area of?"<<endl;
cin>> Jole;
if (Jole == "a")
{cout<<"Please enter the value of one side."<< endl;
cin>> x;
cout<< "The area is "<< x * x;}
if (Jole == "Triangle")
{cout<<"Please enter the value of the height."<<endl;
cin>> h;
cout<<"and Now the base length"<<endl;
cin>> u;
cout<< "The area is "<< 0.5*(h * u);}
if (Jole == "Trapezium")
{cout<<"Please enter the length of the top line."<<cta;
cin>> a;
cout<<cta<<"Now please enter the length of the bottom line"<<cta;
cin>> b;
cout<<cta<<"Now enter the height (vertical distance from the top to bottom)"<<cta;
cin>> H;
cout<<cta<<"The area of the trapezium is "<< H*((a + b) * 0.5);}
}
because I have attempted the latter, And despite their existence in the header, it doesn’t recognise variables
But it may be too late to make several classes, I have 30 days left and a functioning slingshot, the only issue is the momentum conservation which is is the reason I posted this topic. In future I’ll be less minimal with classes but can we please sort out the issue? With it solved I can move on the make the game even more playable
Well, to be honest, the terms you use make it hard to understand what you actually want/need. I read your post a few times and we have to take the time to imagine what you are saying.
Example:
What does this even mean to anyone besides you? We have to try and stop and imagine your scene and imagine your sprites and imagine the ball moving and, and, and. Then look at your code, then say ok, he has code and it does this…imagining how the code applies to the imagined scene we just imagined…
just use shapes and numbers.
ball has a velocity of 10.
ball collides with wall.
The wall takes away some of the velocity of the ball, say 8, 2 remaining.
I want to take the 2 remaining and add that to the previous velocity from the last attempt. Or if this was the first attempt add the remaining to a default value.
You are asking us to help develop your game. You don’t really want concepts you want specific code to solve your specific problem.
You don’t post pictures all the time
You don’t post all the relevant code. You post what you think we want.
You argue when we give you advice or say the advice isn’t for you. Or just to help you with what you have.
We are here to teach, not write your game for you.
I only asked how to stop mass conservation? A simple line. I would send an image to make it simpler but I fear that all I’d get in return is criticism for not using classes. But simply put, I want to use a code like this:
physicsBody-> **xyz**
in a collision method to give the body a neutral mass. Your suggested method didn’t work I am sorry to say
You make it seem my entire game is just code from the forum glued together. This is no-where near the case. I see the forum as a last resort after at least a day of unsuccessful in-depth research into an issue, this happened to be one of those circumstances
Partly :), I reposition the ball and spawn the joint.
Sorry to cause suspicion, you do not see the attempts as the moment I find out they don’t work I just erase it
but from my many attempts I tried to addMasssetMasssetDynamic(false)setVelocityLimitsetVelocity
As the setposition way causes lag, I use a null speed moveto. This causes the ball to reload based on the velocity on collsion <-- something I have been frantically trying to fix
Ok, A picture tells a thousand words so I made a youtube video. Please skip to 0:08
and notice how, when the ball is launched lightly and collides with the floor, it re-loads very lightly. When I launch the ball into the ground at a high speed it respawns so fast you cannot control it. This is the code of the method, perhaps I can add something to it to make it have no dynamicy and then dynamicy, but if I try this I get an abort error:
Why are you not allowing gravity to effect things?
If I think about how a slingshot would work you would pull back and let go. The more I pull back the faster and farther the ball should go. If the ball hits something going fast it will lose some speed but still be fast. If the ball hits something slowly it will lose some speed but still be slow or even just fall to the ground if it is to slow.
I’d think that you need to look at setVelocity,setMoment, setLinearDamping
This is what the slingshot joint connects to. It is a non collidable invisible block which, on release, is removed. The ball is hooked with gravity and does normal physics
Here it is when it’s not invisible:
(very tiny green spec above the ball) this is why I called it the slingdot
the ball is connected to that spec with a spring joint. On release this dot is removed, casing the ball to launch
Upon analysis of the video, what do you think is best. I have tried velocity and already use lineardamping, but they both failed to replicate the ball at the beginning, as damping made the ball slower than the last and velocity doesn’t actually change the hole conservation issue but I’ll have a look at the moment.