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

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


Utilizing BezierTo on a Sprite I be aware 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. Nonetheless it’s on a person curve outlined in BezierTo that the sprite slows down and hurries up.

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 virtually stops. Settings the factors to be equally distanced alongside the road solves this for Bezier straight traces, however I’m not utilizing Bezier curves for traces, this identical behaviour is exhibited on curves and that is problematic.

Instance 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.


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

Hello, I’m new to Cocos and to those boards, however not new to coding. Sadly transferring at a continuing velocity, or creating equidistant factors alongside a Bezier is a little more difficult. It’s a must to work out a sequence of factors alongside the curve first after which interpolate alongside that, which implies you most likely solely need to work out all of the factors as soon as up entrance and retailer them. Some Bezier libraries will help this utilization out of the field. There’s a good tutorial / rationalization on youtube, it’s for unity, however the language is fairly comparable… edit I’m not allowed to hyperlink it however for those who search “Sebastian Lague bezier curve editor” on YT it is best to discover it simply.

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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments