Player node's position resets to origin

Hi,

Recently, I’ve been using .linearVelocity in collision detection code that accesses the cc.RigidBody component via a variable, inside the “update” function. This script component is attached to the player node, and when .linearVelocity is applied to the node (this.node.linearVelocity) or a variable, the node’s position is automatically set to (0, 0) even when there is nothing in the code causing this to be the case. There are also no indicators in the Cocos Creator and web browser consoles as to what could be the problem. The position also sets to the origin during some basic mathematical calculations involving variables as well. I’ve tried using setPosition(); to remedy this, but to no avail. Any help given would be greatly appreciated. Thanks.

We can ask @jare to have a team member look at this. Is there any code you can share to help show us?

Not sure what the problem is. Can you upload a demo to reproduce the problem?

Sure.

ErrorExample.zip (279.6 KB)

I should also add that I’m using version 1.9 of the software.

The rigidbody.linearVelocity type is cc.Vec2. Did you set a number value to body.linearVelocity?
The document is here: https://docs.cocos2d-x.org/creator/1.10/api/en/classes/RigidBody.html#linearvelocity

1 Like

Yes, that fixed it. Thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.