Tuesday, September 13, 2022
HomeGame DevelopmentBezierTo doesn't transfer at fixed velocity - cocos2d-x

BezierTo doesn’t transfer at fixed velocity – cocos2d-x

Using BezierTo on a Sprite I notice that it strikes at totally different speeds at totally different locations on the curve. Any options for this?

I’ve a path made up of curves, for every curve I calculate the size after which use that size to calculate the time. However it’s on a person curve outlined in BezierTo that the sprite slows down and quickens.

I’ve demoed this within the video under setting the curve as a straight line. You do that by setting management level 1 to the top and management level 2 to the start with a time of two seconds. The sprite will get slower the nearer to the center it will get till nearly stops. Settings the factors to be equally distanced alongside the road solves this for Bezier straight strains, however I’m not utilizing Bezier curves for strains, this identical behaviour is exhibited on curves and that is problematic.

Example of not fixed velocity on a curve. A bit arduous to see however the sprite picks up a little bit of velocity when hitting the curve within the centre of the display.

This is the ensuing behaviour of Bezier curve maths for getting the X and Y factors at a share of the entire curve, 0% being the beginning level and 100% being the top level of the curve and all different percentages being the factors in between. Cocos2nd works by getting the present X and Y with the proportion being the time handed since beginning the transfer and the entire time the complete transfer will take. So 5 seconds into a ten second transfer will get the purpose at 50%.

Hi, I’m new to Cocos and to those boards, however not new to coding. Unfortunately transferring at a relentless velocity, or creating equidistant factors alongside a Bezier is a little more sophisticated. You should work out a collection of factors alongside the curve first after which interpolate alongside that, which suggests you in all probability solely wish to work out all of the factors as soon as up entrance and retailer them. Some Bezier libraries will assist this utilization out of the field. There is an efficient tutorial / clarification on youtube, it’s for unity, however the language is fairly related… edit I’m not allowed to hyperlink it however should you search “Sebastian Lague bezier curve editor” on YT it is best to discover it simply.

Thanks. This is what I did ultimately, went over the curve and pre-calculated the factors alongside it utilizing the size by way of the curve as t.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments